diff --git a/extend/catcher/CatchAdmin.php b/extend/catcher/CatchAdmin.php index de279ad..ef3556b 100644 --- a/extend/catcher/CatchAdmin.php +++ b/extend/catcher/CatchAdmin.php @@ -189,10 +189,10 @@ class CatchAdmin foreach (self::getModulesDirectory() as $module) { if (is_dir($module)) { $moduleInfo = self::getModuleInfo($module); - if (isset($moduleInfo['services']) && !empty($moduleInfo['services'])) { - if ($moduleInfo['enable']) { - $services = array_merge($services, $moduleInfo['services']); - } + // 如果没有设置 module.json 默认加载 + $moduleServices = $moduleInfo['services'] ?? []; + if (!empty($moduleServices) && $moduleInfo['enable']) { + $services = array_merge($services, $moduleServices); } } } @@ -231,7 +231,7 @@ class CatchAdmin * @param $module * @return bool */ - public function disableModule($module) + public static function disableModule($module) { $moduleJson = self::moduleDirectory($module) . 'module.json'; @@ -241,7 +241,7 @@ class CatchAdmin $info = \json_decode(file_get_contents($moduleJson), true); - $info['enable'] = true; + $info['enable'] = false; file_put_contents($moduleJson, \json_encode($info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); @@ -280,7 +280,6 @@ class CatchAdmin if (file_exists($module . DIRECTORY_SEPARATOR . 'module.json')) { return \json_decode(file_get_contents($module. DIRECTORY_SEPARATOR . 'module.json'), true); } - return []; } diff --git a/extend/catcher/command/install/DisableModuleCommand.php b/extend/catcher/command/install/DisableModuleCommand.php new file mode 100644 index 0000000..98b8d57 --- /dev/null +++ b/extend/catcher/command/install/DisableModuleCommand.php @@ -0,0 +1,41 @@ +setName('disable:module') + ->addArgument('module', Argument::REQUIRED, 'module name') + ->setDescription('disable catch module'); + } + + protected function execute(Input $input, Output $output) + { + $module = $input->getArgument('module'); + + //dd($module, 123); + if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) { + $output->error("module [$module] not exist"); + } else { + CatchAdmin::disableModule($module); + $output->info("module [$module] disabled"); + } + } +} \ No newline at end of file diff --git a/extend/catcher/command/install/EnableModuleCommand.php b/extend/catcher/command/install/EnableModuleCommand.php new file mode 100644 index 0000000..4df2841 --- /dev/null +++ b/extend/catcher/command/install/EnableModuleCommand.php @@ -0,0 +1,39 @@ +setName('enable:module') + ->addArgument('module', Argument::REQUIRED, 'module name') + ->setDescription('enable catch module'); + } + + protected function execute(Input $input, Output $output) + { + $module = $input->getArgument('module'); + + if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) { + $output->error("module [$module] not exist"); + } else { + CatchAdmin::enableModule($module); + $output->info("module [$module] enabled"); + } + } +} \ No newline at end of file