예제 #1
0
 public function match(Route $route)
 {
     uksort($this->map, function ($path1, $path2) {
         $path1Length = strlen($path1);
         $path2Length = strlen($path2);
         return $path1Length == $path2Length ? 0 : ($path1Length < $path2Length ? 1 : -1);
     });
     $missingPath = $route->getMissingPath();
     foreach ($this->map as $path => $parameters) {
         if (stripos($missingPath, $path) !== 0) {
             continue;
         }
         if (!$this->allowPartialMatches && strtolower(trim($path, '/')) != strtolower(trim($missingPath, '/'))) {
             continue;
         }
         $route->matchPath($path);
         foreach ($parameters as $key => $value) {
             $route->setParameter($key, $value);
         }
         if (trim($route->getMissingPath(), '/') == '') {
             $route->found();
         }
         break;
     }
 }
예제 #2
0
 public function match(Route $route)
 {
     if (stripos($route->getMissingPath(), $this->pathPrefix) !== 0) {
         return;
     }
     $route->matchPath($this->pathPrefix, false);
     $this->apply($route, $this->matchers, $this->factory);
 }
예제 #3
0
 /**
  * Finds the longest matching path.
  *
  * @param Route     $route
  * @param mixed[][] $map
  * @param bool      $allowPartialMatches
  */
 protected function matchRegularExpressions(Route $route, array $map, bool $allowPartialMatches)
 {
     $paths = [];
     $missingPath = $route->getMissingPath();
     foreach ($map as $regex => $parameters) {
         if (!preg_match('#' . $regex . '#i', $missingPath, $matches)) {
             continue;
         }
         $match = $matches[0];
         if (!$allowPartialMatches && strtolower(trim($match, '/')) != strtolower(trim($missingPath, '/'))) {
             continue;
         }
         if (isset($paths[$match])) {
             throw new \RuntimeException(sprintf('Multiple regular expressions match "%s".', $match));
         }
         $paths[$match] = $parameters;
         foreach ($matches as $key => $value) {
             if (is_string($key)) {
                 $paths[$match][$key] = $value;
             }
         }
     }
     if (count($paths) == 0) {
         return;
     }
     uksort($paths, function ($path1, $path2) {
         $path1Length = strlen($path1);
         $path2Length = strlen($path2);
         return $path1Length == $path2Length ? 0 : ($path1Length < $path2Length ? 1 : -1);
     });
     $parameters = reset($paths);
     $path = key($paths);
     $route->matchPath($path);
     foreach ($parameters as $key => $value) {
         $route->setParameter($key, $value);
     }
     if (trim($route->getMissingPath(), '/') == '') {
         $route->found();
     }
 }