Ejemplo n.º 1
0
 /**
  * Find a matching route to the current PATH_INFO and inject
  * returning values to the Request object.
  *
  * @throws EvHttp_Controller_Router_Exception
  * @return EvHttp_Controller_Request_Abstract Request object
  */
 public function route(EvHttp_Controller_Request_Abstract $request)
 {
     if (!$request instanceof EvHttp_Controller_Request_Http) {
         require_once 'EvHttp/Controller/Router/Exception.php';
         throw new EvHttp_Controller_Router_Exception('EvHttp_Controller_Router_Rewrite requires a EvHttp_Controller_Request_Http-based request object');
     }
     if ($this->_useDefaultRoutes) {
         $this->addDefaultRoutes();
     }
     // Find the matching route
     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;
             break;
         }
     }
     return $request;
 }