/** * Call a user action * * @param string $controller_name Name of the controller to call * @param string $method_name * @todo, moving this to middleware would be great. */ private function call_action($controller_name, $method_name) { if ($controller_name != 'Controller' && class_exists($controller_name, true)) { Controller::setToupti($this); $controller = new $controller_name(); if (method_exists($controller, $method_name)) { if ($controller->isAuthorized($method_name)) { $this->response->body = $controller->{$method_name}(); // \o/ good job, can exit now return; } else { throw new TouptiException('access_not_allowed', 403); } } else { throw new TouptiException('Route error. Action ' . $method_name . ' not exist in ' . $controller_name . ' for ' . $this->request->original_uri . '.', 404); } } throw new TouptiException('Route error. Controller ' . $controller_name . ' not found for ' . $this->request->original_uri . '.', 404); }