mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 04:28:41 +00:00
Module init restructure
This commit is contained in:
parent
d7289adf9e
commit
1b0837af1e
|
|
@ -426,25 +426,35 @@ class ModuleManager
|
||||||
public function initModule($module)
|
public function initModule($module)
|
||||||
{
|
{
|
||||||
if (is_array($module)) {
|
if (is_array($module)) {
|
||||||
foreach ($module as $m) {
|
$this->initModuleArray($module);
|
||||||
try {
|
|
||||||
$this->initModule($m);
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
$this->app->logger->warning(FileLogger::MSG_FULL, [
|
|
||||||
'message' => 'Trying to initialize ' . $m . ' without controller.',
|
|
||||||
'line' => $e->getLine(),
|
|
||||||
'file' => $e->getFile(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif (is_string($module) && realpath(self::MODULE_PATH . '/' . $module . '/Controller.php') !== false) {
|
} elseif (is_string($module) && realpath(self::MODULE_PATH . '/' . $module . '/Controller.php') !== false) {
|
||||||
$this->running[$module] = ModuleFactory::getInstance($module, $this->app);
|
$this->initModuleController($module);
|
||||||
$this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller');
|
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('Invalid Module');
|
throw new \InvalidArgumentException('Invalid Module');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function initModuleArray(array $modules)
|
||||||
|
{
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
try {
|
||||||
|
$this->initModule($module);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
$this->app->logger->warning(FileLogger::MSG_FULL, [
|
||||||
|
'message' => 'Trying to initialize ' . $module . ' without controller.',
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function initModuleController(string $module)
|
||||||
|
{
|
||||||
|
$this->running[$module] = ModuleFactory::getInstance($module, $this->app);
|
||||||
|
$this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get module instance.
|
* Get module instance.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user