/** * Loads controller defined by the request object. * * @return \Ilch\Controller\Base */ protected function loadController() { $controllerName = $this->request->getControllerName(); $findSub = strpos($controllerName, '_'); $dir = ''; if ($findSub !== false) { $controllerParts = explode('_', $this->request->getControllerName()); $controllerName = $controllerParts[1]; $dir = ucfirst($controllerParts[0]) . '\\'; } if ($this->request->isAdmin()) { $controller = '\\Modules\\' . ucfirst($this->request->getModuleName()) . '\\Controllers\\Admin\\' . $dir . ucfirst($controllerName); } else { $controller = '\\Modules\\' . ucfirst($this->request->getModuleName()) . '\\Controllers\\' . $dir . ucfirst($controllerName); } //TODO: React properly for controllers / modules / actions that don't exist $controller = new $controller($this->layout, $this->view, $this->request, $this->router, $this->translator); $action = $this->request->getActionName() . 'Action'; $this->plugin->addPluginData('controller', $controller); $this->plugin->execute('BeforeControllerLoad'); if (method_exists($controller, 'init')) { $controller->init(); } if (method_exists($controller, $action)) { $controller->{$action}(); } return $controller; }