2023-04-09 12:11:14 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\store\source;
|
|
|
|
|
|
|
|
|
|
use JetBrains\PhpStorm\ArrayShape;
|
|
|
|
|
use SPC\exception\DownloaderException;
|
|
|
|
|
use SPC\store\Downloader;
|
|
|
|
|
|
|
|
|
|
class PhpSource extends CustomSourceBase
|
|
|
|
|
{
|
|
|
|
|
public const NAME = 'php-src';
|
|
|
|
|
|
2025-03-30 23:27:43 +08:00
|
|
|
public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void
|
2023-04-09 12:11:14 +08:00
|
|
|
{
|
2025-07-15 21:14:15 +08:00
|
|
|
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
|
|
|
|
|
if ($major === '8.5') {
|
2025-11-16 11:30:40 +01:00
|
|
|
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~daniels/php-8.5.0RC5.tar.xz'], $force);
|
2025-07-28 15:36:53 +08:00
|
|
|
} elseif ($major === 'git') {
|
|
|
|
|
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
|
2025-07-15 21:14:15 +08:00
|
|
|
} else {
|
2025-09-29 21:15:18 +02:00
|
|
|
Downloader::downloadSource('php-src', $this->getLatestPHPInfo($major), $force);
|
2025-07-15 21:14:15 +08:00
|
|
|
}
|
2023-04-09 12:11:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 PHP x.y 的具体版本号,例如通过 8.1 来获取 8.1.10
|
|
|
|
|
*/
|
|
|
|
|
#[ArrayShape(['type' => 'string', 'path' => 'string', 'rev' => 'string', 'url' => 'string'])]
|
|
|
|
|
public function getLatestPHPInfo(string $major_version): array
|
|
|
|
|
{
|
|
|
|
|
// 查找最新的小版本号
|
2024-03-10 16:23:30 +08:00
|
|
|
$info = json_decode(Downloader::curlExec(
|
|
|
|
|
url: "https://www.php.net/releases/index.php?json&version={$major_version}",
|
2025-09-29 21:15:56 +02:00
|
|
|
retries: (int) getenv('SPC_DOWNLOAD_RETRIES') ?: 0
|
2024-03-10 16:23:30 +08:00
|
|
|
), true);
|
2023-08-25 17:35:14 +02:00
|
|
|
if (!isset($info['version'])) {
|
|
|
|
|
throw new DownloaderException("Version {$major_version} not found.");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 12:11:14 +08:00
|
|
|
$version = $info['version'];
|
|
|
|
|
|
|
|
|
|
// 从官网直接下载
|
|
|
|
|
return [
|
|
|
|
|
'type' => 'url',
|
2024-07-07 20:45:18 +08:00
|
|
|
'url' => "https://www.php.net/distributions/php-{$version}.tar.xz",
|
2023-04-09 12:11:14 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|