Repository navigation
Add PECL download type and support for PECL artifacts #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ext-ast: | ||
| type: php-extension | ||
| artifact: | ||
| source: | ||
| type: pecl | ||
| name: ast |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace StaticPHP\Artifact\Downloader\Type; | ||
|
|
||
| use StaticPHP\Artifact\ArtifactDownloader; | ||
| use StaticPHP\Artifact\Downloader\DownloadResult; | ||
| use StaticPHP\Exception\DownloaderException; | ||
|
|
||
| /* pecl */ | ||
| class PECL implements DownloadTypeInterface, CheckUpdateInterface | ||
| { | ||
| private const string PECL_BASE_URL = 'https://pecl.php.net'; | ||
|
|
||
| /** REST API: returns XML with <r><v>VERSION</v><s>STATE</s></r> per release */ | ||
| private const string PECL_REST_URL = 'https://pecl.php.net/rest/r/%s/allreleases.xml'; | ||
|
|
||
| public function checkUpdate(string $name, array $config, ?string $old_version, ArtifactDownloader $downloader): CheckUpdateResult | ||
| { | ||
| [, $version] = $this->fetchPECLInfo($name, $config, $downloader); | ||
| return new CheckUpdateResult( | ||
| old: $old_version, | ||
| new: $version, | ||
| needUpdate: $old_version === null || version_compare($version, $old_version, '>'), | ||
| ); | ||
| } | ||
|
|
||
| public function download(string $name, array $config, ArtifactDownloader $downloader): DownloadResult | ||
| { | ||
| [$filename, $version] = $this->fetchPECLInfo($name, $config, $downloader); | ||
| $url = self::PECL_BASE_URL . '/get/' . $filename; | ||
| $path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . $filename; | ||
| logger()->debug("Downloading {$name} from URL: {$url}"); | ||
| default_shell()->executeCurlDownload($url, $path, retries: $downloader->getRetry()); | ||
| $extract = $config['extract'] ?? ('php-src/ext/' . $this->getExtractName($name)); | ||
| return DownloadResult::archive($filename, $config, $extract, version: $version, downloader: static::class); | ||
| } | ||
|
|
||
| protected function fetchPECLInfo(string $name, array $config, ArtifactDownloader $downloader): array | ||
| { | ||
| $peclName = strtolower($config['name'] ?? $this->getExtractName($name)); | ||
| $url = sprintf(self::PECL_REST_URL, $peclName); | ||
|
crazywhalecc marked this conversation as resolved.
Resolved
|
||
| logger()->debug("Fetching PECL release list for {$name} from REST API"); | ||
| $xml = default_shell()->executeCurl($url, retries: $downloader->getRetry()); | ||
| if ($xml === false) { | ||
| throw new DownloaderException("Failed to fetch PECL release list for {$name}"); | ||
| } | ||
| // Match <r><v>VERSION</v><s>STATE</s></r> | ||
| preg_match_all('/<r><v>(?P<version>[^<]+)<\/v><s>(?P<state>[^<]+)<\/s><\/r>/', $xml, $matches); | ||
| if (empty($matches['version'])) { | ||
| throw new DownloaderException("Failed to parse PECL release list for {$name}"); | ||
| } | ||
| $versions = []; | ||
| logger()->debug('Matched ' . count($matches['version']) . " releases for {$name} from PECL"); | ||
| foreach ($matches['version'] as $i => $version) { | ||
| if ($matches['state'][$i] !== 'stable') { | ||
| continue; | ||
| } | ||
| $versions[$version] = $peclName . '-' . $version . '.tgz'; | ||
| } | ||
| if (empty($versions)) { | ||
| throw new DownloaderException("No stable releases found for {$name} on PECL"); | ||
| } | ||
| uksort($versions, 'version_compare'); | ||
| $filename = end($versions); | ||
| $version = array_key_last($versions); | ||
| return [$filename, $version, $versions]; | ||
| } | ||
|
|
||
| /** | ||
| * Derive the lowercase PECL package / extract name from the artifact name. | ||
| * e.g. "ext-apcu" -> "apcu", "ext-ast" -> "ast" | ||
| */ | ||
| private function getExtractName(string $name): string | ||
| { | ||
| return strtolower(preg_replace('/^ext-/i', '', $name)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.