Use constant to set internal and filter extensions

This commit is contained in:
crazywhalecc
2024-06-09 11:35:12 +08:00
parent f21522eb9c
commit 442c620da0
3 changed files with 36 additions and 13 deletions

View File

@@ -145,20 +145,26 @@ abstract class BaseCommand extends Command
return static::FAILURE; 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 protected function parseExtensionList(string $ext_list): array
{ {
$ext_list = str_replace('zend-opcache', 'opcache', $ext_list); // replace alias
$a = array_map('trim', explode(',', $ext_list)); $ls = array_map(function ($x) {
return array_values(array_filter($a, function ($x) { $lower = strtolower(trim($x));
$filter_internals = [ if (isset(SPC_EXTENSION_ALIAS[$lower])) {
'core', logger()->notice("Extension [{$lower}] is an alias of [" . SPC_EXTENSION_ALIAS[$lower] . '], it will be replaced.');
'hash', return SPC_EXTENSION_ALIAS[$lower];
'json', }
'reflection', return $lower;
'spl', }, explode(',', $ext_list));
'standard',
]; // filter internals
if (in_array(strtolower($x), $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."); logger()->warning("Extension [{$x}] is an builtin extension, it will be ignored.");
return false; return false;
} }

View File

@@ -38,6 +38,23 @@ const DANGER_CMD = [
'rmdir', '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 // file replace strategy
const REPLACE_FILE_STR = 1; const REPLACE_FILE_STR = 1;
const REPLACE_FILE_PREG = 2; const REPLACE_FILE_PREG = 2;

View File

@@ -19,7 +19,7 @@ $upx = true;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $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', 'Windows' => 'mbstring,pdo_sqlite,mbregex',
}; };