From 205ffcc49b3ee61581f654948a49ff3998cfafe3 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Thu, 14 May 2015 12:50:23 +0200 Subject: [PATCH 1/2] Added Application::getControllerClass($route). --- b8/Application.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/b8/Application.php b/b8/Application.php index 7c9c5f9..fc0a8cc 100755 --- a/b8/Application.php +++ b/b8/Application.php @@ -79,9 +79,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 +95,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) From 46938e4f56f8fd8fdc6182635b4e2b8f11f4b97a Mon Sep 17 00:00:00 2001 From: Adirelle Date: Thu, 14 May 2015 12:50:50 +0200 Subject: [PATCH 2/2] Application: throws a 404 error when the controller doesn't exist. --- b8/Application.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/b8/Application.php b/b8/Application.php index fc0a8cc..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); }