From 2d2607cd7f24dc161bafe90e4c665ceb61eee4a8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 9 Jun 2024 13:38:50 +0200 Subject: [PATCH] replace ext-zend-opcache with ext-opcache for spc extension list (#475) * replace ext-zend-opcache with ext-opcache for spc extension list * Use constant to set internal and filter extensions --------- Co-authored-by: Marc Henderkes Co-authored-by: crazywhalecc --- src/SPC/command/BaseCommand.php | 29 ++++++++++++++++++----------- src/globals/defines.php | 17 +++++++++++++++++ src/globals/test-extensions.php | 2 +- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/SPC/command/BaseCommand.php b/src/SPC/command/BaseCommand.php index cfb72e26..d67b133a 100644 --- a/src/SPC/command/BaseCommand.php +++ b/src/SPC/command/BaseCommand.php @@ -145,19 +145,26 @@ abstract class BaseCommand extends Command return static::FAILURE; } + /** + * Parse extension list from string, replace alias and filter internal extensions. + * + * @param string $ext_list Extension string list, e.g. "mbstring,posix,sockets" + */ protected function parseExtensionList(string $ext_list): array { - $a = array_map('trim', explode(',', $ext_list)); - return array_values(array_filter($a, function ($x) { - $filter_internals = [ - 'core', - 'hash', - 'json', - 'reflection', - 'spl', - 'standard', - ]; - if (in_array(strtolower($x), $filter_internals)) { + // replace alias + $ls = array_map(function ($x) { + $lower = strtolower(trim($x)); + if (isset(SPC_EXTENSION_ALIAS[$lower])) { + logger()->notice("Extension [{$lower}] is an alias of [" . SPC_EXTENSION_ALIAS[$lower] . '], it will be replaced.'); + return SPC_EXTENSION_ALIAS[$lower]; + } + return $lower; + }, explode(',', $ext_list)); + + // filter internals + return array_values(array_filter($ls, function ($x) { + if (in_array($x, SPC_INTERNAL_EXTENSIONS)) { logger()->warning("Extension [{$x}] is an builtin extension, it will be ignored."); return false; } diff --git a/src/globals/defines.php b/src/globals/defines.php index 94a9ff9e..b1868756 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -38,6 +38,23 @@ const DANGER_CMD = [ 'rmdir', ]; +// spc internal extensions +const SPC_INTERNAL_EXTENSIONS = [ + 'core', + 'hash', + 'json', + 'reflection', + 'spl', + 'standard', +]; + +// spc extension alias +const SPC_EXTENSION_ALIAS = [ + 'zend opcache' => 'opcache', + 'zend-opcache' => 'opcache', + 'zendopcache' => 'opcache', +]; + // file replace strategy const REPLACE_FILE_STR = 1; const REPLACE_FILE_PREG = 2; diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 6a3cf7ba..16aff9e9 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,7 +19,7 @@ $upx = true; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'libxml,xlswriter,openssl,core,hash,json,standard,SPL,HASH,REFLECTION', + 'Linux', 'Darwin' => 'libxml,xlswriter,openssl,core,hash,json,standard,SPL,HASH,REFLECTION,zend-opcache', 'Windows' => 'mbstring,pdo_sqlite,mbregex', };