Exemplo n.º 1
0
 /**
  * Find a matching route to the current PATH_INFO and inject
  * returning values to the Request object.
  *
  * @throws IfwPsn_Vendor_Zend_Controller_Router_Exception
  * @return IfwPsn_Vendor_Zend_Controller_Request_Abstract Request object
  */
 public function route(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request)
 {
     if (!$request instanceof IfwPsn_Vendor_Zend_Controller_Request_Http) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Router/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Router_Exception('IfwPsn_Vendor_Zend_Controller_Router_Rewrite requires a IfwPsn_Vendor_Zend_Controller_Request_Http-based request object');
     }
     if ($this->_useDefaultRoutes) {
         $this->addDefaultRoutes();
     }
     // Find the matching route
     $routeMatched = false;
     foreach (array_reverse($this->_routes, true) 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 IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Router/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Router_Exception('No route matched the request', 404);
     }
     if ($this->_useCurrentParamsAsGlobal) {
         $params = $request->getParams();
         foreach ($params as $param => $value) {
             $this->setGlobalParam($param, $value);
         }
     }
     return $request;
 }