优化开启/关闭模块

This commit is contained in:
JaguarJack
2020-06-24 10:07:11 +08:00
parent f6783cb13e
commit 5f5260a639
3 changed files with 86 additions and 7 deletions

View File

@@ -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 [];
}