diff --git a/b8/Application.php b/b8/Application.php index 7c9c5f9..b2cf069 100755 --- a/b8/Application.php +++ b/b8/Application.php @@ -66,6 +66,10 @@ public function handleRequest() $action = lcfirst($this->toPhpName($this->route['action'])); + if (!$this->controllerExists($this->route)) { + throw new NotFoundException('Route not found'); + } + if (!$this->getController()->hasAction($action)) { throw new NotFoundException('Controller ' . $this->toPhpName($this->route['controller']) . ' does not have action ' . $action); } @@ -79,9 +83,7 @@ public function handleRequest() public function getController() { if (empty($this->controller)) { - $namespace = $this->toPhpName($this->route['namespace']); - $controller = $this->toPhpName($this->route['controller']); - $controllerClass = $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; + $controllerClass = $this->getControllerClass($this->route); $this->controller = $this->loadController($controllerClass); } @@ -97,13 +99,15 @@ protected function loadController($class) } protected function controllerExists($route) + { + return class_exists($this->getControllerClass($route)); + } + + protected function getControllerClass($route) { $namespace = $this->toPhpName($route['namespace']); $controller = $this->toPhpName($route['controller']); - - $controllerClass = $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; - - return class_exists($controllerClass); + return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; } public function isValidRoute($route)