Index: tests/Zend/Controller/Router/RewriteTest.php =================================================================== --- tests/Zend/Controller/Router/RewriteTest.php (Revision 19836) +++ tests/Zend/Controller/Router/RewriteTest.php (Arbeitskopie) @@ -263,10 +263,15 @@ $this->_router->addRoute('default', new Zend_Controller_Router_Route(':controller/:action')); - $token = $this->_router->route($request); + try { + $token = $this->_router->route($request); + $this->fail('An expected Zend_Controller_Router_Exception was not raised'); + } catch (Zend_Controller_Router_Exception $expected) { + $this->assertEquals('No route matched the request', $expected->getMessage()); + } - $this->assertNull($token->getControllerName()); - $this->assertNull($token->getActionName()); + $this->assertNull($request->getControllerName()); + $this->assertNull($request->getActionName()); } public function testDefaultRouteMatched() @@ -381,7 +386,12 @@ $request = new Zend_Controller_Router_RewriteTest_Request('http://localhost/ctrl/act'); $this->_router->removeDefaultRoutes(); - $token = $this->_router->route($request); + try { + $token = $this->_router->route($request); + $this->fail('An expected Zend_Controller_Router_Exception was not raised'); + } catch (Zend_Controller_Router_Exception $expected) { + $this->assertEquals('No route matched the request', $expected->getMessage()); + } $routes = $this->_router->getRoutes(); $this->assertEquals(0, count($routes)); Index: library/Zend/Controller/Router/Rewrite.php =================================================================== --- library/Zend/Controller/Router/Rewrite.php (Revision 19836) +++ library/Zend/Controller/Router/Rewrite.php (Arbeitskopie) @@ -380,6 +380,8 @@ } // Find the matching route + $routeMatched = false; + foreach (array_reverse($this->_routes) as $name => $route) { // TODO: Should be an interface method. Hack for 1.0 BC if (method_exists($route, 'isAbstract') && $route->isAbstract()) { @@ -396,10 +398,16 @@ if ($params = $route->match($match)) { $this->_setRequestParams($request, $params); $this->_currentRoute = $name; + $routeMatched = true; break; } } + if (!$routeMatched) { + require_once 'Zend/Controller/Router/Exception.php'; + throw new Zend_Controller_Router_Exception('No route matched the request', 404); + } + if($this->_useCurrentParamsAsGlobal) { $params = $request->getParams(); foreach($params as $param => $value) { Index: library/Zend/Controller/Front.php =================================================================== --- library/Zend/Controller/Front.php (Revision 19836) +++ library/Zend/Controller/Front.php (Arbeitskopie) @@ -907,8 +907,16 @@ */ $this->_plugins->routeStartup($this->_request); - $router->route($this->_request); + try { + $router->route($this->_request); + } catch (Exception $e) { + if ($this->throwExceptions()) { + throw $e; + } + $this->_response->setException($e); + } + /** * Notify plugins of router completion */ Index: library/Zend/Controller/Plugin/ErrorHandler.php =================================================================== --- library/Zend/Controller/Plugin/ErrorHandler.php (Revision 19836) +++ library/Zend/Controller/Plugin/ErrorHandler.php (Arbeitskopie) @@ -47,6 +47,11 @@ const EXCEPTION_NO_ACTION = 'EXCEPTION_NO_ACTION'; /** + * Const - No route exception; no routing was possible + */ + const EXCEPTION_NO_ROUTE = 'EXCEPTION_NO_ROUTE'; + + /** * Const - Other Exception; exceptions thrown by application controllers */ const EXCEPTION_OTHER = 'EXCEPTION_OTHER'; @@ -187,16 +192,36 @@ } /** - * postDispatch() plugin hook -- check for exceptions and dispatch error - * handler if necessary + * Route shutdown hook -- Ccheck for router exceptions + * + * @param Zend_Controller_Request_Abstract $request + */ + public function routeShutdown(Zend_Controller_Request_Abstract $request) + { + $this->_handleError($request); + } + + /** + * Post dispatch hook -- check for exceptions and dispatch error handler if + * necessary * + * @param Zend_Controller_Request_Abstract $request + */ + public function postDispatch(Zend_Controller_Request_Abstract $request) + { + $this->_handleError($request); + } + + /** + * Handle errors and exceptions + * * If the 'noErrorHandler' front controller flag has been set, * returns early. * * @param Zend_Controller_Request_Abstract $request * @return void */ - public function postDispatch(Zend_Controller_Request_Abstract $request) + protected function _handleError(Zend_Controller_Request_Abstract $request) { $frontController = Zend_Controller_Front::getInstance(); if ($frontController->getParam('noErrorHandler')) { @@ -225,6 +250,13 @@ $exceptionType = get_class($exception); $error->exception = $exception; switch ($exceptionType) { + case 'Zend_Controller_Router_Exception': + if (404 == $exception->getCode()) { + $error->type = self::EXCEPTION_NO_ROUTE; + } else { + $error->type = self::EXCEPTION_OTHER; + } + break; case 'Zend_Controller_Dispatcher_Exception': $error->type = self::EXCEPTION_NO_CONTROLLER; break;