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

@@ -96,13 +96,32 @@ const SPC_STATUS_ALREADY_BUILT = 1;
const SPC_DOWNLOAD_TYPE_DISPLAY_NAME = [
'bitbuckettag' => 'BitBucket',
'filelist' => 'website',
'filelist' => 'File index website',
'git' => 'git',
'ghrel' => 'GitHub release',
'ghtar', 'ghtagtar' => 'GitHub tarball',
'ghtar' => 'GitHub release tarball',
'ghtagtar' => 'GitHub tag tarball',
'local' => 'local dir',
'pie' => 'PHP Installer for Extensions',
'pie' => 'PHP Installer for Extensions (PIE)',
'url' => 'url',
'php-release' => 'php.net',
'custom' => 'custom downloader',
];
const SUPPORTED_OS_CATEGORY = [
'unix',
'windows',
'linux',
'macos',
];
const SUPPORTED_OS_FAMILY = [
'Linux',
'Darwin',
'Windows',
];
const SPC_MODE_SOURCE = 1;
const SPC_MODE_VENDOR = 2;
const SPC_MODE_PHAR = 4;
const SPC_MODE_VENDOR_PHAR = SPC_MODE_VENDOR | SPC_MODE_PHAR;

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
*/