From 6b0baa8365894106aaac24d6ee2c791a303d0bc0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 19 Mar 2023 01:16:54 +0800 Subject: [PATCH] add more extensions support --- config/ext.json | 3 ++- ext-support.md | 39 ++++++++++++++++++------------------ src/SPC/store/Downloader.php | 25 ++++++++++++++++++++--- src/globals/tests/filter.php | 5 +++++ src/globals/tests/zip.php | 5 +++++ src/globals/tests/zlib.php | 5 +++++ 6 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 src/globals/tests/filter.php create mode 100644 src/globals/tests/zip.php create mode 100644 src/globals/tests/zlib.php diff --git a/config/ext.json b/config/ext.json index 4c85461d..2f572385 100644 --- a/config/ext.json +++ b/config/ext.json @@ -30,7 +30,8 @@ "type": "builtin", "arg-type-windows": "with", "lib-depends": [ - "libxml2" + "libxml2", + "zlib" ] }, "enchant": { diff --git a/ext-support.md b/ext-support.md index 6b1ea97a..ecf1720f 100644 --- a/ext-support.md +++ b/ext-support.md @@ -10,53 +10,54 @@ | bcmath | | yes | | | bz2 | | untested | | | calendar | | yes | | -| ctype | | | | +| ctype | | yes | | | curl | | yes | | | date | | yes | | -| dom | | | | +| dom | | untested | | | event | | | | -| exif | | | | -| filter | | | | +| exif | | yes | | +| filter | | yes | | | fileinfo | | | | -| ftp | | | | +| ftp | | yes | | | gd | | untested | | | gmp | | untested | | | hash | | yes | | | iconv | | | | | inotify | | | | | json | | yes | | -| libxml | | | | -| mbstring | | | | +| libxml | | yes | | +| mbstring | | yes | | | mcrypt | | | | | mongodb | | | | | mysqli | | | | -| mysqlnd | | | | +| mysqlnd | | yes | | | openssl | | yes | | | pcntl | | untested | | | pcre | | yes | | | pdo | | yes | | -| pdo_mysql | | | | +| pdo_mysql | | yes | | | pdo_sqlite | | yes | | | pdo_pgsql | | | | -| phar | | | | -| posix | | | | +| phar | | yes | | +| posix | | yes | | | protobuf | | | | | readline | | | | -| redis | | | | +| redis | | yes | | | Reflection | | yes | | +| session | | yes | | | shmop | | | | -| simplexml | | | | +| simplexml | | untested | | | soap | | | | | sockets | | | | | sqlite3 | | untested | | | swow | | | | | swoole | | yes | | -| tokenizer | | | | -| xml | | | | -| xmlreader | | | | -| xmlwriter | | | | -| zip | | | | -| zlib | | | | +| tokenizer | | yes | | +| xml | | yes | | +| xmlreader | | untested | | +| xmlwriter | | untested | | +| zip | | yes | | +| zlib | | yes | | ## Additional Requirements diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index fcd4db57..d88b0de2 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -184,7 +184,7 @@ class Downloader public static function downloadGit(string $name, string $url, string $branch, ?string $path = null): void { - if ($path) { + if ($path !== null) { $path = SOURCE_PATH . "/{$path}"; } else { $path = DOWNLOAD_PATH . "/{$name}"; @@ -229,7 +229,7 @@ class Downloader public static function fetchSource(string $name, array $source): void { // 避免重复 fetch - if (is_dir(FileSystem::convertPath(SOURCE_PATH . "/{$name}")) || isset($source['path']) && is_dir(FileSystem::convertPath(SOURCE_PATH . "/{$source['path']}"))) { + if (!isset($source['path']) && !is_dir(FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}")) || isset($source['path']) && is_dir(FileSystem::convertPath(SOURCE_PATH . "/{$source['path']}"))) { logger()->notice("{$name} source already extracted"); return; } @@ -291,7 +291,8 @@ class Downloader // 从官网直接下载 return [ 'type' => 'url', - 'url' => "https://www.php.net/distributions/php-{$version}.tar.gz", + // 'url' => "https://www.php.net/distributions/php-{$version}.tar.gz", + 'url' => "https://mirrors.zhamao.xin/php/php-{$version}.tar.gz", ]; } @@ -316,6 +317,24 @@ class Downloader $headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers)); $cmd = "curl -sfSL {$methodArg} {$headerArg} \"{$url}\""; + if (getenv('CACHE_API_EXEC') === 'yes') { + if (!file_exists(SOURCE_PATH . '/.curl_exec_cache')) { + $cache = []; + } else { + $cache = json_decode(file_get_contents(SOURCE_PATH . '/.curl_exec_cache'), true); + } + if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) { + return $cache[$cmd]['cache']; + } + f_exec($cmd, $output, $ret); + if ($ret !== 0) { + throw new DownloaderException('failed http fetch'); + } + $cache[$cmd]['cache'] = implode("\n", $output); + $cache[$cmd]['expire'] = time() + 3600; + file_put_contents(SOURCE_PATH . '/.curl_exec_cache', json_encode($cache)); + return $cache[$cmd]['cache']; + } f_exec($cmd, $output, $ret); if ($ret !== 0) { throw new DownloaderException('failed http fetch'); diff --git a/src/globals/tests/filter.php b/src/globals/tests/filter.php new file mode 100644 index 00000000..ec5fb591 --- /dev/null +++ b/src/globals/tests/filter.php @@ -0,0 +1,5 @@ +