From 61ece52edc9cf7c54ccdce45f34f88369614bbde Mon Sep 17 00:00:00 2001 From: sunxyw Date: Wed, 21 Dec 2022 00:13:53 +0800 Subject: [PATCH 1/5] fix init command dir --- src/ZM/Command/InitCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ZM/Command/InitCommand.php b/src/ZM/Command/InitCommand.php index ff2c5d6e..411a7372 100644 --- a/src/ZM/Command/InitCommand.php +++ b/src/ZM/Command/InitCommand.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\OutputInterface; use ZM\Exception\InitException; +use ZM\Utils\ZMUtil; #[AsCommand(name: 'init', description: '初始化框架运行的基础文件')] class InitCommand extends Command @@ -185,7 +186,7 @@ class InitCommand extends Command private function getVendorPath(string $file): string { try { - $package_name = json_decode(file_get_contents(__DIR__ . '/../../../composer.json'), true, 512, JSON_THROW_ON_ERROR)['name']; + $package_name = ZMUtil::getComposerMetadata()['name']; } catch (\JsonException) { throw new InitException('无法读取框架包的 composer.json', '请检查框架包完整性,或者重新安装框架包'); } From 8901c3163100dc528b28fe94ea32ec4f97def585 Mon Sep 17 00:00:00 2001 From: sunxyw Date: Wed, 21 Dec 2022 00:28:02 +0800 Subject: [PATCH 2/5] fix command loader relative path --- src/ZM/Command/InitCommand.php | 12 ++++-------- src/ZM/ConsoleApplication.php | 14 +++++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ZM/Command/InitCommand.php b/src/ZM/Command/InitCommand.php index 411a7372..0be2c245 100644 --- a/src/ZM/Command/InitCommand.php +++ b/src/ZM/Command/InitCommand.php @@ -9,7 +9,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\OutputInterface; use ZM\Exception\InitException; -use ZM\Utils\ZMUtil; #[AsCommand(name: 'init', description: '初始化框架运行的基础文件')] class InitCommand extends Command @@ -46,7 +45,9 @@ class InitCommand extends Command 'Custom\\' => 'src/Custom', ], 'files' => [ - 'src/Custom/global_function.php', + 'src/Globals/global_functions.php', + 'src/Globals/global_defines_app.php', + 'src/Globals/global_class_alias.php', ], ]; @@ -185,12 +186,7 @@ class InitCommand extends Command private function getVendorPath(string $file): string { - try { - $package_name = ZMUtil::getComposerMetadata()['name']; - } catch (\JsonException) { - throw new InitException('无法读取框架包的 composer.json', '请检查框架包完整性,或者重新安装框架包'); - } - return $this->base_path . '/vendor/' . $package_name . $file; + return FRAMEWORK_ROOT_DIR . $file; } private function extractFiles(array $files, OutputInterface $output): void diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php index a20fd9a0..3399a9eb 100644 --- a/src/ZM/ConsoleApplication.php +++ b/src/ZM/ConsoleApplication.php @@ -28,7 +28,19 @@ final class ConsoleApplication extends Application } // 初始化命令 - $command_classes = FileSystem::getClassesPsr4(zm_dir('src/ZM/Command'), 'ZM\\Command'); + $command_classes = []; + // 先加载框架内置命令 + $command_classes = array_merge( + $command_classes, + FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\\Command') + ); + // 再加载用户自定义命令(如存在) + if (is_dir(zm_dir('src/Command'))) { + $command_classes = array_merge( + $command_classes, + FileSystem::getClassesPsr4(zm_dir('src/Command'), 'Command') + ); + } $commands = []; foreach ($command_classes as $command_class) { try { From 4554bbc85b4745e9edb09baa5eea6b5b65ef68df Mon Sep 17 00:00:00 2001 From: sunxyw Date: Wed, 21 Dec 2022 00:34:08 +0800 Subject: [PATCH 3/5] remove internal files from extract list --- src/ZM/Command/InitCommand.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ZM/Command/InitCommand.php b/src/ZM/Command/InitCommand.php index 0be2c245..73ab2bd6 100644 --- a/src/ZM/Command/InitCommand.php +++ b/src/ZM/Command/InitCommand.php @@ -44,11 +44,7 @@ class InitCommand extends Command 'Module\\' => 'src/Module', 'Custom\\' => 'src/Custom', ], - 'files' => [ - 'src/Globals/global_functions.php', - 'src/Globals/global_defines_app.php', - 'src/Globals/global_class_alias.php', - ], + 'files' => [], ]; $section->write('更新 composer.json ... '); @@ -119,7 +115,6 @@ class InitCommand extends Command '/zhamao', '/.gitignore', '/config/*', - '/src/Globals/*.php', ]; return $this->getFilesFromPatterns($patterns); From 3f2bd69002efb67178b7713440782657380afb59 Mon Sep 17 00:00:00 2001 From: sunxyw Date: Wed, 21 Dec 2022 00:38:37 +0800 Subject: [PATCH 4/5] fix global define bootstrapper relative path --- src/ZM/Bootstrap/LoadGlobalDefines.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZM/Bootstrap/LoadGlobalDefines.php b/src/ZM/Bootstrap/LoadGlobalDefines.php index 1c1b45ea..356a9c24 100644 --- a/src/ZM/Bootstrap/LoadGlobalDefines.php +++ b/src/ZM/Bootstrap/LoadGlobalDefines.php @@ -8,6 +8,6 @@ class LoadGlobalDefines { public function bootstrap(array $config): void { - require zm_dir(SOURCE_ROOT_DIR . '/src/Globals/global_defines_framework.php'); + require FRAMEWORK_ROOT_DIR . '/src/Globals/global_defines_framework.php'; } } From 9bf95223a16e2f9cc37c805dc0e7493acae0730f Mon Sep 17 00:00:00 2001 From: sunxyw Date: Wed, 21 Dec 2022 01:19:45 +0800 Subject: [PATCH 5/5] fix user command dir path --- src/ZM/ConsoleApplication.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php index 3399a9eb..bff0bc07 100644 --- a/src/ZM/ConsoleApplication.php +++ b/src/ZM/ConsoleApplication.php @@ -35,10 +35,10 @@ final class ConsoleApplication extends Application FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\\Command') ); // 再加载用户自定义命令(如存在) - if (is_dir(zm_dir('src/Command'))) { + if (is_dir(SOURCE_ROOT_DIR . '/src/Command')) { $command_classes = array_merge( $command_classes, - FileSystem::getClassesPsr4(zm_dir('src/Command'), 'Command') + FileSystem::getClassesPsr4(SOURCE_ROOT_DIR . '/src/Command', 'Command') ); } $commands = [];