优化开启/关闭模块
This commit is contained in:
parent
f6783cb13e
commit
5f5260a639
@ -189,10 +189,10 @@ class CatchAdmin
|
|||||||
foreach (self::getModulesDirectory() as $module) {
|
foreach (self::getModulesDirectory() as $module) {
|
||||||
if (is_dir($module)) {
|
if (is_dir($module)) {
|
||||||
$moduleInfo = self::getModuleInfo($module);
|
$moduleInfo = self::getModuleInfo($module);
|
||||||
if (isset($moduleInfo['services']) && !empty($moduleInfo['services'])) {
|
// 如果没有设置 module.json 默认加载
|
||||||
if ($moduleInfo['enable']) {
|
$moduleServices = $moduleInfo['services'] ?? [];
|
||||||
$services = array_merge($services, $moduleInfo['services']);
|
if (!empty($moduleServices) && $moduleInfo['enable']) {
|
||||||
}
|
$services = array_merge($services, $moduleServices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ class CatchAdmin
|
|||||||
* @param $module
|
* @param $module
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function disableModule($module)
|
public static function disableModule($module)
|
||||||
{
|
{
|
||||||
$moduleJson = self::moduleDirectory($module) . 'module.json';
|
$moduleJson = self::moduleDirectory($module) . 'module.json';
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ class CatchAdmin
|
|||||||
|
|
||||||
$info = \json_decode(file_get_contents($moduleJson), true);
|
$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));
|
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')) {
|
if (file_exists($module . DIRECTORY_SEPARATOR . 'module.json')) {
|
||||||
return \json_decode(file_get_contents($module. DIRECTORY_SEPARATOR . 'module.json'), true);
|
return \json_decode(file_get_contents($module. DIRECTORY_SEPARATOR . 'module.json'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
extend/catcher/command/install/DisableModuleCommand.php
Normal file
41
extend/catcher/command/install/DisableModuleCommand.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\command\install;
|
||||||
|
|
||||||
|
use catcher\CatchAdmin;
|
||||||
|
use think\console\Command;
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\input\Argument;
|
||||||
|
use think\console\input\Option;
|
||||||
|
use think\console\Output;
|
||||||
|
|
||||||
|
class DisableModuleCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
extend/catcher/command/install/EnableModuleCommand.php
Normal file
39
extend/catcher/command/install/EnableModuleCommand.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\command\install;
|
||||||
|
|
||||||
|
use catcher\CatchAdmin;
|
||||||
|
use think\console\Command;
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\input\Argument;
|
||||||
|
use think\console\Output;
|
||||||
|
|
||||||
|
class EnableModuleCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user