Module init restructure

This commit is contained in:
Dennis Eichhorn 2016-04-02 17:25:41 +02:00
parent d7289adf9e
commit 1b0837af1e

View File

@ -426,23 +426,33 @@ 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);
} elseif (is_string($module) && realpath(self::MODULE_PATH . '/' . $module . '/Controller.php') !== false) {
$this->initModuleController($module);
} else {
throw new \InvalidArgumentException('Invalid Module');
}
}
private function initModuleArray(array $modules)
{
foreach ($modules as $module) {
try { try {
$this->initModule($m); $this->initModule($module);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$this->app->logger->warning(FileLogger::MSG_FULL, [ $this->app->logger->warning(FileLogger::MSG_FULL, [
'message' => 'Trying to initialize ' . $m . ' without controller.', 'message' => 'Trying to initialize ' . $module . ' without controller.',
'line' => $e->getLine(), 'line' => $e->getLine(),
'file' => $e->getFile(), 'file' => $e->getFile(),
]); ]);
} }
} }
} elseif (is_string($module) && realpath(self::MODULE_PATH . '/' . $module . '/Controller.php') !== false) { }
private function initModuleController(string $module)
{
$this->running[$module] = ModuleFactory::getInstance($module, $this->app); $this->running[$module] = ModuleFactory::getInstance($module, $this->app);
$this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller'); $this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller');
} else {
throw new \InvalidArgumentException('Invalid Module');
}
} }
/** /**