Author: Shivam Mathur (shivammathur)
Date: 2025-11-19T01:58:56+05:30
Commit:
https://github.com/php/web-downloads/commit/4d745948835100a7330af3f08dbedcd6b06a2548
Raw diff:
https://github.com/php/web-downloads/commit/4d745948835100a7330af3f08dbedcd6b06a2548.diff
Add support to update packages.txt file
Changed paths:
M src/Console/Command/WinlibsCommand.php
M tests/Console/Command/WinlibsCommandTest.php
Diff:
diff --git a/src/Console/Command/WinlibsCommand.php
b/src/Console/Command/WinlibsCommand.php
index 1edc3a7..40888d9 100644
--- a/src/Console/Command/WinlibsCommand.php
+++ b/src/Console/Command/WinlibsCommand.php
@@ -47,7 +47,7 @@ public function handle(): int
if ($files) {
if($data['type'] === 'php') {
$this->copyPhpFiles($files, $data['library'],
$data['vs_version_targets']);
- $this->updateSeriesFiles(
+ $this->updatePhpSeriesFiles(
$files,
$data['library'],
$data['php_versions'],
@@ -56,6 +56,7 @@ public function handle(): int
);
} else {
$this->copyPeclFiles($files, $data['library']);
+ $this->updatePackagesFile($files, $data['library']);
}
}
@@ -124,7 +125,7 @@ private function copyPeclFiles(array $files, string
$library): void
}
}
- private function updateSeriesFiles(
+ private function updatePhpSeriesFiles(
array $files,
string $library,
string $php_versions,
@@ -170,4 +171,45 @@ private function updateSeriesFiles(
}
}
}
+
+ private function updatePackagesFile(array $files, string $library): void
+ {
+ $baseDirectory = $this->baseDirectory . "/pecl/deps";
+ $packagesFile = $baseDirectory . "/packages.txt";
+ $syncFile = $packagesFile . '.sync';
+
+ if (!is_dir($baseDirectory)) {
+ mkdir($baseDirectory, 0755, true);
+ }
+
+ $file_lines = [];
+ if (file_exists($packagesFile)) {
+ $file_lines = file($packagesFile, FILE_IGNORE_NEW_LINES);
+ }
+
+ if(!file_exists($syncFile)) {
+ $file_lines = array_map(function($file) {
+ return basename($file);
+ }, glob($baseDirectory . '/*.zip'));
+ } else {
+ foreach ($files as $file) {
+ $fileName = str_replace($file['artifact_name'], $library,
$file['file_name']);
+ $found = false;
+ foreach ($file_lines as $no => $line) {
+ if (str_starts_with($line, $library)) {
+ $file_lines[$no] = $fileName;
+ $found = true;
+ }
+ }
+ if (!$found) {
+ $file_lines[] = $fileName;
+ }
+ }
+ }
+ sort($file_lines);
+ file_put_contents($packagesFile, implode("\n", $file_lines));
+ if(!file_exists($syncFile)) {
+ touch($syncFile);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/Console/Command/WinlibsCommandTest.php
b/tests/Console/Command/WinlibsCommandTest.php
index c2127c9..db1847b 100644
--- a/tests/Console/Command/WinlibsCommandTest.php
+++ b/tests/Console/Command/WinlibsCommandTest.php
@@ -182,6 +182,53 @@ public function testSuccessfulPeclFileOperations(): void
$this->assertFileExists($this->baseDirectory .
"/pecl/deps/$library-$ref-$vsVersion-$arch.zip");
}
+ public function testPackagesFileIsGeneratedWithoutSyncFile(): void
+ {
+ $result = $this->runPeclWinlibsCommand('redis', 'phpredis', '5.3.7',
'vs16', 'x64');
+
+ $this->assertEquals(0, $result, 'Command should return success.');
+
+ $packagesFile = $this->baseDirectory . '/pecl/deps/packages.txt';
+ $syncFile = $packagesFile . '.sync';
+
+ $this->assertFileExists($packagesFile);
+ $this->assertFileExists($syncFile);
+ $this->assertSame(
+ ['phpredis-5.3.7-vs16-x64.zip'],
+ file($packagesFile, FILE_IGNORE_NEW_LINES)
+ );
+ }
+
+ public function
testPackagesFileUpdatesExistingEntriesAndMaintainsSorting(): void
+ {
+ $this->runPeclWinlibsCommand('redis', 'phpredis', '5.3.7', 'vs16',
'x64');
+
+ $packagesFile = $this->baseDirectory . '/pecl/deps/packages.txt';
+ $this->assertFileExists($packagesFile);
+ $this->assertSame(
+ ['phpredis-5.3.7-vs16-x64.zip'],
+ file($packagesFile, FILE_IGNORE_NEW_LINES)
+ );
+
+ $this->runPeclWinlibsCommand('imagick', 'imagick', '3.7.0', 'vs16',
'x64');
+ $this->assertSame(
+ [
+ 'imagick-3.7.0-vs16-x64.zip',
+ 'phpredis-5.3.7-vs16-x64.zip',
+ ],
+ file($packagesFile, FILE_IGNORE_NEW_LINES)
+ );
+
+ $this->runPeclWinlibsCommand('redis', 'phpredis', '5.3.8', 'vs16',
'x64');
+ $this->assertSame(
+ [
+ 'imagick-3.7.0-vs16-x64.zip',
+ 'phpredis-5.3.8-vs16-x64.zip',
+ ],
+ file($packagesFile, FILE_IGNORE_NEW_LINES)
+ );
+ }
+
public static function versionProvider(): array
{
return [
@@ -278,4 +325,32 @@ public static function fileProvider(): array
]],
];
}
+
+ private function runPeclWinlibsCommand(string $buildName, string $library,
string $ref, string $vsVersion, string $arch): int
+ {
+ $directory = $this->winlibsDirectory . '/' . $buildName;
+ mkdir($directory, 0755, true);
+
+ file_put_contents($directory . '/data.json', json_encode([
+ 'type' => 'pecl',
+ 'library' => $library,
+ 'ref' => $ref,
+ 'vs_version_targets' => $vsVersion,
+ 'php_versions' => '8.2',
+ 'stability' => 'stable'
+ ]));
+
+ $zipPath = $directory . "/$buildName-$ref-$vsVersion-$arch.zip";
+ $zip = new ZipArchive();
+ if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
+ $zip->addFromString('dummy_file.txt', 'dummy content');
+ $zip->close();
+ }
+
+ $command = new WinlibsCommand();
+ $command->setOption('base-directory', $this->baseDirectory);
+ $command->setOption('builds-directory', $this->buildsDirectory);
+
+ return $command->handle();
+ }
}