/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws \Zend\Controller\Router\Exception * @return \Zend\Controller\Request\AbstractRequest Request object */ public function route(\Zend\Controller\Request\AbstractRequest $request) { if (!$request instanceof \Zend\Controller\Request\HTTP) { require_once 'Zend/Controller/Router/Exception.php'; throw new Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_HTTP-based request object'); } if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } // 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()) { continue; } // TODO: Should be an interface method. Hack for 1.0 BC if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $request->getPathInfo(); } else { $match = $request; } 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 Exception('No route matched the request', 404); } if ($this->_useCurrentParamsAsGlobal) { $params = $request->getParams(); foreach ($params as $param => $value) { $this->setGlobalParam($param, $value); } } return $request; }