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;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
2023-04-09 12:11:14 +08:00
|
|
|
use SPC\store\Downloader;
|
|
|
|
|
|
|
|
|
|
class PhpSource extends CustomSourceBase
|
|
|
|
|
{
|
|
|
|
|
public const NAME = 'php-src';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws DownloaderException
|
2023-08-20 19:51:45 +08:00
|
|
|
* @throws FileSystemException
|
2023-04-09 12:11:14 +08:00
|
|
|
*/
|
2024-03-10 10:58:58 +08:00
|
|
|
public function fetch(bool $force = false): void
|
2023-04-09 12:11:14 +08:00
|
|
|
{
|
|
|
|
|
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1';
|
2024-03-10 10:58:58 +08:00
|
|
|
Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force);
|
2023-04-09 12:11:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 PHP x.y 的具体版本号,例如通过 8.1 来获取 8.1.10
|
|
|
|
|
*
|
|
|
|
|
* @throws DownloaderException
|
|
|
|
|
*/
|
|
|
|
|
#[ArrayShape(['type' => 'string', 'path' => 'string', 'rev' => 'string', 'url' => 'string'])]
|
|
|
|
|
public function getLatestPHPInfo(string $major_version): array
|
|
|
|
|
{
|
|
|
|
|
// 查找最新的小版本号
|
|
|
|
|
$info = json_decode(Downloader::curlExec(url: "https://www.php.net/releases/index.php?json&version={$major_version}"), 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',
|
|
|
|
|
'url' => "https://www.php.net/distributions/php-{$version}.tar.gz",
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|