Example #1
0
 private function _routeRequestByRewriteRoutes()
 {
     $requestPath = $this->_request->path;
     foreach (self::$_routes as $routeName => $route) {
         preg_match_all($route->pattern, $requestPath, $patternMatches);
         if (count($patternMatches) > 0 && count($patternMatches[0]) > 0) {
             self::$_currentRoute = $route;
             $routeParams = array('controller' => self::GetDashedFromPascalCase(isset($route->controller) ? $route->controller : ''), 'action' => self::GetDashedFromPascalCase(isset($route->action) ? $route->action : ''));
             preg_match_all("#{%([a-zA-Z0-9]*)}#", $route->reverse, $reverseMatches);
             if (isset($reverseMatches[1]) && $reverseMatches[1]) {
                 $reverseMatchesNames = $reverseMatches[1];
                 array_shift($patternMatches);
                 foreach ($reverseMatchesNames as $key => $reverseKey) {
                     if (isset($patternMatches[$key]) && count($patternMatches[$key])) {
                         $routeParams[$reverseKey] = $patternMatches[$key][0];
                     } else {
                         break;
                     }
                 }
             }
             $routeDefaultParams = isset($route->params) ? $route->params : array();
             $this->_request->params = array_merge($routeDefaultParams, $this->_request->params, $routeParams);
             break;
         }
     }
 }