diff --git a/bin/spc b/bin/spc index 18dd3a38..09d92995 100755 --- a/bin/spc +++ b/bin/spc @@ -9,12 +9,12 @@ if (PHP_OS_FAMILY !== 'Windows' && PHP_BINARY !== (__DIR__ . '/php') && file_exi pcntl_exec(__DIR__ . '/php', $argv); } -if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) { - // Current: ./bin (git/project mode) - require_once dirname(__DIR__) . '/vendor/autoload.php'; -} else { +if (file_exists(dirname(__DIR__, 3) . '/autoload.php')) { // Current: ./vendor/crazywhalecc/static-php-cli/bin (composer library mode) require_once dirname(__DIR__, 3) . '/autoload.php'; +} else { + // Current: ./bin (git/project mode) + require_once dirname(__DIR__) . '/vendor/autoload.php'; } // 防止 Micro 打包状态下不支持中文的显示(虽然这个项目目前好像没输出过中文?) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index bab8a008..bc65be9f 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -30,7 +30,7 @@ /** * static-php-cli console app entry */ -final class ConsoleApplication extends Application +class ConsoleApplication extends Application { public const VERSION = '2.5.2'; diff --git a/src/SPC/builder/BuilderProvider.php b/src/SPC/builder/BuilderProvider.php index 18636952..038e97af 100644 --- a/src/SPC/builder/BuilderProvider.php +++ b/src/SPC/builder/BuilderProvider.php @@ -36,6 +36,7 @@ public static function makeBuilderByInput(InputInterface $input): BuilderBase 'BSD' => new BSDBuilder($input->getOptions()), default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'), }; + return self::$builder; } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 4c8df333..8b635fec 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -98,6 +98,12 @@ public function proveLibs(array $sorted_libraries): void ROOT_DIR . '/src/SPC/builder/' . osfamily2dir() . '/library', 'SPC\builder\\' . osfamily2dir() . '\library' ); + if (file_exists(WORKING_DIR . '/src/builder/' . osfamily2dir() . '/library')) { + $classes = array_merge($classes, FileSystem::getClassesPsr4( + WORKING_DIR . '/src/builder/' . osfamily2dir() . '/library', + 'App\builder\\' . osfamily2dir() . '\library' + )); + } foreach ($classes as $class) { if (defined($class . '::NAME') && $class::NAME !== 'unknown' && Config::getLib($class::NAME) !== null) { $support_lib_list[$class::NAME] = $class; diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 7a604ca8..99ef7a18 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -223,6 +223,12 @@ public function proveLibs(array $sorted_libraries): void ROOT_DIR . '\src\SPC\builder\\' . osfamily2dir() . '\library', 'SPC\builder\\' . osfamily2dir() . '\library' ); + if (file_exists(WORKING_DIR . '\src\builder\\' . osfamily2dir() . '\library')) { + $classes = array_merge($classes, FileSystem::getClassesPsr4( + WORKING_DIR . '\src\builder\\' . osfamily2dir() . '\library', + 'App\builder\\' . osfamily2dir() . '\library' + )); + } foreach ($classes as $class) { if (defined($class . '::NAME') && $class::NAME !== 'unknown' && Config::getLib($class::NAME) !== null) { $support_lib_list[$class::NAME] = $class; diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index 7117bb3f..8b9f2b51 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -372,6 +372,12 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f break; case 'custom': // Custom download method, like API-based download or other $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source'); + if (file_exists(WORKING_DIR . '/src/store/source')) { + $classes = array_merge($classes, FileSystem::getClassesPsr4( + WORKING_DIR . '/src/store/source', + 'App\store\source' + )); + } foreach ($classes as $class) { if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) { (new $class())->fetch($force); @@ -483,6 +489,12 @@ public static function downloadSource(string $name, ?array $source = null, bool break; } $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source'); + if (file_exists(WORKING_DIR . '/src/store/source')) { + $classes = array_merge($classes, FileSystem::getClassesPsr4( + WORKING_DIR . '/src/store/source', + 'App\store\source' + )); + } foreach ($classes as $class) { if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) { (new $class())->fetch($force, $source, $download_as); diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 16047427..262c4271 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -24,16 +24,25 @@ public static function loadConfigArray(string $config, ?string $config_dir = nul WORKING_DIR . '/config/' . $config . '.json', ROOT_DIR . '/config/' . $config . '.json', ]; + + $all = []; foreach ($tries as $try) { if (file_exists($try)) { $json = json_decode(self::readFile($try), true); if (!is_array($json)) { throw new FileSystemException('Reading ' . $try . ' failed'); } - return $json; + $all = array_merge($json, $all); } } - throw new FileSystemException('Reading ' . $config . '.json failed'); + + ksort($all); + + if (count($all) === 0) { + throw new FileSystemException('Reading ' . $config . '.json failed'); + } + + return $all; } /** diff --git a/src/SPC/util/CustomExt.php b/src/SPC/util/CustomExt.php index bbd4adf7..38689a50 100644 --- a/src/SPC/util/CustomExt.php +++ b/src/SPC/util/CustomExt.php @@ -24,6 +24,9 @@ public function __construct(protected string $ext_name) {} public static function loadCustomExt(): void { $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/builder/extension', 'SPC\builder\extension'); + if (file_exists(WORKING_DIR . '/src/builder/extension')) { + $classes = array_merge($classes, FileSystem::getClassesPsr4(WORKING_DIR . '/src/builder/extension', 'App\builder\extension')); + } foreach ($classes as $class) { $reflection = new \ReflectionClass($class); foreach ($reflection->getAttributes(CustomExt::class) as $attribute) {