コード例 #1
0
ファイル: AbstractMatcher.php プロジェクト: rokite/windwalker
 /**
  * Match routes.
  *
  * @param string $route
  * @param Route  $routeItem
  *
  * @return  Route|false
  */
 public function matchRoute($route, Route $routeItem)
 {
     $regex = $routeItem->getRegex();
     if (!$regex || $this->debug) {
         $regex = BasicCompiler::compile($routeItem->getPattern(), $routeItem->getRequirements());
         $routeItem->setRegex($regex);
     }
     $route = RouteHelper::normalise($route);
     if (preg_match($regex, $route, $matches)) {
         $variables = RouteHelper::getVariables($matches);
         $variables['_rawRoute'] = $route;
     } else {
         return false;
     }
     $routeItem->setVariables(array_merge($routeItem->getVariables(), $variables));
     return $routeItem;
 }
コード例 #2
0
 /**
  * Match routes.
  *
  * @param string $route
  * @param string $method
  * @param array  $options
  *
  * @return  Route|false
  */
 public function match($route, $method = 'GET', $options = array())
 {
     $route = RouteHelper::normalise($route);
     $this->count = 0;
     $this->buildRouteMaps();
     $keys = array_keys($this->routeMaps);
     $left = 0;
     $right = count($this->routeMaps) - 1;
     while ($left <= $right) {
         $middle = round(($left + $right) / 2);
         $key = $keys[$middle];
         $routeItem = $this->routes[$this->routeMaps[$key]];
         $this->count++;
         if ($this->matchOptions($routeItem, $method, $options) && $this->matchRoute($route, $routeItem)) {
             return $routeItem;
         }
         if (strcmp($route, $key) < 0) {
             $right = $middle - 1;
         } else {
             $left = $middle + 1;
         }
     }
     return false;
 }
コード例 #3
0
ファイル: Router.php プロジェクト: rokite/windwalker
 /**
  * buildRoute
  *
  * @param string $name
  * @param array  $queries
  * @param bool   $rootSlash
  *
  * @return string
  */
 public function build($name, $queries = array(), $rootSlash = false)
 {
     if (!array_key_exists($name, $this->routes)) {
         throw new \OutOfRangeException('Route: ' . $name . ' not found.');
     }
     $route = $this->matcher->build($this->routes[$name], (array) $queries);
     if ($rootSlash) {
         return RouteHelper::normalise($route);
     }
     return ltrim($route, '/');
 }
コード例 #4
0
 /**
  * setPattern
  *
  * @param   string $pattern
  *
  * @return  Route  Return self to support chaining.
  */
 public function setPattern($pattern)
 {
     $this->pattern = RouteHelper::normalise($pattern);
     return $this;
 }