Add lib skeleton command and sort config, spc_mode suuport, etc...

This commit is contained in:
crazywhalecc
2025-12-18 15:43:58 +08:00
parent 1707c679e8
commit dd5762fbd3
19 changed files with 866 additions and 109 deletions

View File

@@ -10,6 +10,31 @@ use StaticPHP\Runtime\Shell\UnixShell;
use StaticPHP\Runtime\Shell\WindowsCmd;
use ZM\Logger\ConsoleLogger;
/**
* Get the current SPC loading mode. If passed a mode to check, will return whether current mode matches the given mode.
*/
function spc_mode(?int $check_mode = null): bool|int
{
$mode = SPC_MODE_SOURCE;
// if current file is in phar, then it's phar mode
if (str_starts_with(__FILE__, 'phar://') && Phar::running()) {
// judge whether it's vendor mode (inside vendor/) or source mode (inside src/)
if (basename(dirname(__FILE__, 3)) === 'static-php-cli' && basename(dirname(__FILE__, 5)) === 'vendor') {
$mode = SPC_MODE_VENDOR_PHAR;
} else {
$mode = SPC_MODE_PHAR;
}
} elseif (basename(dirname(__FILE__, 3)) === 'static-php-cli' && basename(dirname(__FILE__, 5)) === 'vendor') {
$mode = SPC_MODE_VENDOR;
}
if ($check_mode === null) {
return $mode;
}
// use bitwise AND to check mode
return ($mode & $check_mode) !== 0;
}
/**
* Judge if an array is an associative array
*/