dependences
This commit is contained in:
parent
e29108f21d
commit
2711c0258d
@ -33,6 +33,7 @@ function getConst($text): array|false|string
|
||||
];
|
||||
|
||||
$str = $text;
|
||||
|
||||
foreach($constStr as $key => $value)
|
||||
{
|
||||
$str = str_replace($key, $value, $str);
|
||||
|
@ -24,10 +24,10 @@ class ModuleController extends AdminController
|
||||
|
||||
public function actionIndex(): void
|
||||
{
|
||||
$admin_theme_paths = Option::where("key", "module_paths")->first();
|
||||
$module_paths = Option::where("key", "module_paths")->first();
|
||||
$dirs = [];
|
||||
if ($admin_theme_paths){
|
||||
$path = json_decode($admin_theme_paths->value);
|
||||
if ($module_paths){
|
||||
$path = json_decode($module_paths->value);
|
||||
foreach ($path->paths as $p){
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
|
@ -7,5 +7,6 @@
|
||||
"module_class": "kernel\\modules\\post\\PostModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/post/PostModule.php",
|
||||
"routs": "routs/post.php",
|
||||
"migration_path": "migrations"
|
||||
"migration_path": "migrations",
|
||||
"dependence": "user"
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use kernel\console\Out;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
@ -47,20 +46,32 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function toggleModule(string $module): void
|
||||
{
|
||||
$active_modules = Option::where("key", "active_modules")->first();
|
||||
$path = json_decode($active_modules->value);
|
||||
if (in_array($module, $path->modules)) {
|
||||
unset($path->modules[array_search($module, $path->modules)]);
|
||||
$path->modules = array_values($path->modules);
|
||||
$active_modules_info = Option::where("key", "active_modules")->first();
|
||||
$active_modules = json_decode($active_modules_info->value);
|
||||
if (in_array($module, $active_modules->modules)) {
|
||||
unset($active_modules->modules[array_search($module, $active_modules->modules)]);
|
||||
$active_modules->modules = array_values($active_modules->modules);
|
||||
$this->runDeactivateScript($this->getModuleInfoBySlug($module));
|
||||
} else {
|
||||
$path->modules[] = $module;
|
||||
$module_info = $this->getModuleInfoBySlug($module);
|
||||
if (isset($module_info['dependence'])) {
|
||||
$dependence_array = explode(';', $module_info['dependence']);
|
||||
foreach ($dependence_array as $depend) {
|
||||
if (!in_array($depend, $active_modules->modules)) {
|
||||
throw new \Exception("first activate the $depend module");
|
||||
}
|
||||
}
|
||||
}
|
||||
$active_modules->modules[] = $module;
|
||||
$this->runInitScript($this->getModuleInfoBySlug($module));
|
||||
}
|
||||
$active_modules->value = json_encode($path, JSON_UNESCAPED_UNICODE);
|
||||
$active_modules->save();
|
||||
$active_modules_info->value = json_encode($active_modules, JSON_UNESCAPED_UNICODE);
|
||||
$active_modules_info->save();
|
||||
}
|
||||
|
||||
public function getModuleDir(string $slug)
|
||||
|
Loading…
Reference in New Issue
Block a user