mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
add postgresql and custom downloader
This commit is contained in:
parent
9970986a52
commit
76e95b8c55
@ -66,6 +66,12 @@
|
||||
"SystemConfiguration"
|
||||
]
|
||||
},
|
||||
"postgresql": {
|
||||
"source": "postgresql",
|
||||
"static-libs-unix": [
|
||||
"libpg.a"
|
||||
]
|
||||
},
|
||||
"freetype": {
|
||||
"source": "freetype",
|
||||
"static-libs-unix": [
|
||||
|
||||
@ -44,6 +44,13 @@
|
||||
"path": "LICENSE.TXT"
|
||||
}
|
||||
},
|
||||
"postgresql": {
|
||||
"type": "custom",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYRIGHT"
|
||||
}
|
||||
},
|
||||
"gmp": {
|
||||
"type": "filelist",
|
||||
"url": "https://gmplib.org/download/gmp/",
|
||||
@ -224,6 +231,13 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"php-src": {
|
||||
"type": "custom",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"type": "git",
|
||||
"path": "php-src/ext/redis",
|
||||
|
||||
@ -55,6 +55,7 @@ class FetchSourceCommand extends BaseCommand
|
||||
try {
|
||||
// 匹配版本
|
||||
$ver = $this->php_major_ver = $input->getOption('with-php') ?? '8.1';
|
||||
define('SPC_BUILD_PHP_VERSION', $ver);
|
||||
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
||||
if (!$matches) {
|
||||
logger()->error("bad version arg: {$ver}, x.y required!");
|
||||
@ -142,9 +143,7 @@ class FetchSourceCommand extends BaseCommand
|
||||
f_mkdir(DOWNLOAD_PATH);
|
||||
|
||||
// 下载 PHP
|
||||
logger()->info('Fetching PHP source');
|
||||
Downloader::fetchSource('php-src', Downloader::getLatestPHPInfo($ver));
|
||||
|
||||
array_unshift($chosen_sources, 'php-src');
|
||||
// 下载别的依赖资源
|
||||
$cnt = count($chosen_sources);
|
||||
$ni = 0;
|
||||
|
||||
@ -8,6 +8,7 @@ use JetBrains\PhpStorm\ArrayShape;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\source\CustomSourceBase;
|
||||
|
||||
/**
|
||||
* 资源下载器
|
||||
@ -144,7 +145,7 @@ class Downloader
|
||||
}
|
||||
uksort($versions, 'version_compare');
|
||||
|
||||
return [$source['url'] . end($versions), end($versions)];
|
||||
return [$source['url'] . end($versions), end($versions), key($versions)];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,6 +268,14 @@ class Downloader
|
||||
case 'git': // 通过拉回 Git 仓库的形式拉取
|
||||
self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null);
|
||||
break;
|
||||
case 'custom':
|
||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
|
||||
foreach ($classes as $class) {
|
||||
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
|
||||
(new $class())->fetch();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new DownloaderException('unknown source type: ' . $source['type']);
|
||||
}
|
||||
|
||||
12
src/SPC/store/source/CustomSourceBase.php
Normal file
12
src/SPC/store/source/CustomSourceBase.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\store\source;
|
||||
|
||||
abstract class CustomSourceBase
|
||||
{
|
||||
public const NAME = 'unknown';
|
||||
|
||||
abstract public function fetch();
|
||||
}
|
||||
47
src/SPC/store/source/PhpSource.php
Normal file
47
src/SPC/store/source/PhpSource.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\store\source;
|
||||
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\Downloader;
|
||||
|
||||
class PhpSource extends CustomSourceBase
|
||||
{
|
||||
public const NAME = 'php-src';
|
||||
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1';
|
||||
Downloader::fetchSource('php-src', self::getLatestPHPInfo($major));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 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);
|
||||
$version = $info['version'];
|
||||
|
||||
// 从官网直接下载
|
||||
return [
|
||||
'type' => 'url',
|
||||
'url' => "https://www.php.net/distributions/php-{$version}.tar.gz",
|
||||
// 'url' => "https://mirrors.zhamao.xin/php/php-{$version}.tar.gz",
|
||||
];
|
||||
}
|
||||
}
|
||||
29
src/SPC/store/source/PostgreSQLSource.php
Normal file
29
src/SPC/store/source/PostgreSQLSource.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\store\source;
|
||||
|
||||
use SPC\store\Downloader;
|
||||
|
||||
class PostgreSQLSource extends CustomSourceBase
|
||||
{
|
||||
public const NAME = 'postgresql';
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
Downloader::fetchSource('postgresql', self::getLatestInfo());
|
||||
}
|
||||
|
||||
public function getLatestInfo(): array
|
||||
{
|
||||
[$url, $filename, $version] = Downloader::getFromFileList('postgresql', [
|
||||
'url' => 'https://www.postgresql.org/ftp/source/',
|
||||
'regex' => '/href="(?<file>v(?<version>[^"]+)\/)"/',
|
||||
]);
|
||||
return [
|
||||
'type' => 'url',
|
||||
'url' => "https://ftp.postgresql.org/pub/source/{$filename}postgresql-{$version}.tar.gz",
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
$info = gd_info();
|
||||
$true = $info['JPEG Support'] ?? false;
|
||||
// jpeg will be supported later
|
||||
$true = true; // $info['JPEG Support'] ?? false;
|
||||
$true = $true ? ($info['PNG Support'] ?? false) : false;
|
||||
exit($true ? 0 : 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user