@param string $httpMethod
@param string $uri

@return MatchResult
@throws InvalidRouteDataException
974915
public function match($httpMethod, $uri)
    {
        $compiledRouter = $this->getCompiledRouter();

        return MatchResult::fromArray($compiledRouter($httpMethod, $uri));
    }
453648
protected function _parse_search($uri, $route = null, $method = null)
	{
		if ($route === null)
		{
			$route = $this;
		}

		if (is_array($route->translation))
		{
			foreach ($route->translation as $r)
			{
				$verb = $r[0];

				$protocol = isset($r[2]) ? ($r[2] ? 'https' : 'http') : false;

				if (($protocol === false or $protocol == \Input::protocol()) and $method == strtoupper($verb))
				{
					$r[1]->search = $route->search;
					$result = $route->_parse_search($uri, $r[1], $method);

					if ($result)
					{
						return $result;
					}
				}
			}

			return false;
		}

		if ($this->case_sensitive)
		{
			$result = preg_match('#^'.$route->search.'$#uD', $uri, $params);
		}
		else
		{
			$result = preg_match('#^'.$route->search.'$#uiD', $uri, $params);
		}

		if ($result === 1)
		{
			return $route->matched($uri, $params);
		}
		else
		{
			return false;
		}
	}
838375
public function match($methods, $uri, $action)
    {
        return $this->addRoute(\array_map('strtoupper', (array) $methods), $uri, $action);
    }
1208004
private Route matchStandard(String uri, ControllerPath controllerPathObject, AppController controller, HttpMethod method) {

        String controllerPath = (controllerPathObject.getControllerPackage() != null ? "/" + controllerPathObject.getControllerPackage().replace(".", "/") : "") + "/" + controllerPathObject.getControllerName();
        String theUri = uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri;

        //ANY    /package_suffix/controller
        if (controllerPath.length() == theUri.length()) {
            return new Route(controller, "index", method);
        }

        String[] parts;
        try {
            String tail = theUri.substring(controllerPath.length() + 1);
            parts = split(tail, "/");
        } catch (Exception e) {
            throw new RouteException("Failed to parse route from: '" + uri + "'", e);
        }


        //ANY    /package_suffix/controller/action
        if (parts.length == 1) {
            return new Route(controller, parts[0], method);
        }

        //ANY    /package_suffix/controller/action/id/
        if (parts.length == 2) {
            return new Route(controller, parts[0], parts[1], method);
        }
        LOGGER.warn("Failed to find action for request: " + uri);
        return null;
    }
432304
public function dispatch(
        /*# string */ $httpMethod,
        /*# string */ $uriPath,
        array $parameters = []
    )/*# : bool */ {
        // match & dispatch
        if ($this->match($httpMethod, $uriPath, $parameters) &&
            $this->isDispatched()
        ) {
            return true;
        }

        // failed, execute default handler if any
        return $this->defaultHandler();
    }
1284355
public function buildBaseString($uri, array $parameters = [], $httpMethod = 'POST')
    {
        return $this->getBaseStringBuilder()->build($httpMethod, $uri, $parameters);
    }
1193521
protected function checkFallbacks($routes, $httpMethod)
    {
        $additional = array(Route::ANY);

        if ($httpMethod === Route::HEAD) {
            $additional[] = Route::GET;
        }

        foreach ($additional as $method) {
            if (isset($routes[$method])) {
                return $method;
            }
        }

        $this->matchedRoute = $routes;

        throw new HttpMethodNotAllowedException('Allow: ' . implode(', ', array_keys($routes)));
    }
977846
public function matches($uri, $method)
    {
        // Check if request method matches.
        if (in_array($method, $this->methods)) {
            $paramValues = [];

            // Replace parameters with proper regex patterns.
            $urlRegex = preg_replace_callback(self::MATCHES_REGEX, [$this, 'regexUrl'], $this->url);

            // Check if URI matches and if it matches put results in values array.
            $pattern = '@^' . $urlRegex . '/?$@' . ($this->matchUnicode?'u':'');
            if (preg_match($pattern, $uri, $paramValues) === 1) {// There is a match.
                // Extract parameter names.
                $paramNames = [];
                preg_match_all(self::MATCHES_REGEX, $this->url, $paramNames, PREG_PATTERN_ORDER);

                // Put parameters to array to be passed to controller/function later.
                foreach ($paramNames[0] as $index => $value) {
                    $this->params[substr($value, 1)] = urldecode($paramValues[$index + 1]);
                }

                // Append passed params to executable
                $this->executable->addParams($this->params);

                // Everything is done return true.
                return true;
            }
        }
        // No match found return false.
        return false;
    }
221487
public static function findRoute($uri) {
		if(self::$routes === array())
			self::load();

		$count = count($uri);

		$position = &self::$routes;
		for($i = 0; $i < $count; $i++) {
			if($i == $count - 1) {
				if(isset($position[$uri[$i]]) && isset($position[$uri[$i]]["route"])) {
					return $position[$uri[$i]]["route"];
				} else if(isset($position["*"]) && isset($position["*"]["route"])) {
					return $position["*"]["route"];
				} else {
					throw new ValidRouteNotFoundException;
				}
			} else {
				if(isset($position[$uri[$i]])) {
					$position = &$position[$uri[$i]]["children"];
				} elseif(isset($position["*"])) {
					$position = &$position["*"]["children"];
				} else {
					throw new ValidRouteNotFoundException;
				}
			}
		}

		throw new ValidRouteNotFoundException;
	}
1363834
private Route matchRestful(String uri, ControllerPath controllerPathObject, HttpMethod method, AppController controller) {

        String theUri = uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri;
        String controllerPath = (controllerPathObject.getControllerPackage() != null ? "/" + controllerPathObject.getControllerPackage().replace(".", "/") : "") + "/" + controllerPathObject.getControllerName();
        String tail = theUri.length() > controllerPath.length() ? theUri.substring(controllerPath.length() + 1) : "";
        String[] parts = split(tail, "/");

        //GET 	/photos 	            index 	display a list of all photos
        if (controllerPath.equals(theUri) && method.equals(HttpMethod.GET)) {
            return new Route(controller, "index", method);
        }

        //GET 	/photos/new_form 	    new_form        return an HTML form for creating a new photo
        if (parts.length == 1 && method.equals(HttpMethod.GET) && parts[0].equalsIgnoreCase("new_form")) {
            return new Route(controller, "new_form", method);
        }

        //POST 	/photos 	            create 	        create a new photo
        if (parts.length == 0 && method.equals(HttpMethod.POST)) {
            return new Route(controller, "create", method);
        }

        //GET 	/photos/id 	        show            display a specific photo
        if (parts.length == 1 && method.equals(HttpMethod.GET)) {
            return new Route(controller, "show", parts[0], method);
        }

        //GET 	/photos/id/edit_form   edit_form 	    return an HTML form for editing a photo
        if (parts.length == 2 && method.equals(HttpMethod.GET) && parts[1].equalsIgnoreCase("edit_form")) {
            return new Route(controller, "edit_form", parts[0], method);
        }

        //PUT 	/photos/id 	        update          update a specific photo
        if (parts.length == 1 && method.equals(HttpMethod.PUT)) {
            return new Route(controller, "update", parts[0], method);
        }

        //DELETE 	/photos/id 	        destroy         delete a specific photo
        if (parts.length == 1 && method.equals(HttpMethod.DELETE)) {
            return new Route(controller, "destroy", parts[0], method);
        }

        //OPTIONS 	/photos/            options
        if (parts.length == 0 && method.equals(HttpMethod.OPTIONS)) {
            return new Route(controller, "options", method);
        }

        //OPTIONS 	/photos/new_form 	    new_form        return an HTML form for creating a new photo
        if (parts.length == 1 && method.equals(HttpMethod.OPTIONS) && parts[0].equalsIgnoreCase("new_form")) {
            Route r = new Route(controller, "options", parts[0], method);
            r.setTargetAction("new_form");
            return r;

        }

        //OPTIONS 	/photos/id/edit_form 	    edit_form
        if (parts.length == 2 && method.equals(HttpMethod.OPTIONS) && parts[1].equalsIgnoreCase("edit_form")) {
            Route r = new Route(controller, "options", parts[0], method);
            r.setTargetAction("edit_form");
            return r;
        }

        //OPTIONS /photos/id 	        show            display a specific photo
        if (parts.length == 1 && method.equals(HttpMethod.OPTIONS)) {
            Route r = new Route(controller, "options", parts[0], method);
            r.setTargetAction("show");
            return r;
        }

        LOGGER.warn("Failed to find action for request: " + uri);
        return null;
    }
1250681
public function match($path, $method, $action = null)
    {
        $rule = new HttpMethodRule();
        $rule->setPath($path);
        $rule->setMethod($method);
        $rule->setAction($action);
        $rule->setGroup($this);
        $this->children[] = $rule;
        return $rule;
    }
952703
public function addUriWildcards($uri, $reflection, $method): string
    {
        $refAction = $reflection->getReflectionClass()->getMethod($method);

        $parameter = '';
        $patterns = $this->router->getPattern();
        $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters()));

        foreach ($arguments as $key => $param) {
            if (!$param->isOptional()) {
                if (array_key_exists('{:' . $param->getName() . '}', $patterns)) {
                    $slash = ($arguments->hasNext()) ? '/' : '';
                    $parameter .= '{:' . $param->getName() . '}' . $slash;
                }
            }
        }

        return $uri . '/' . $parameter;
    }
243872
public boolean matches(String method, String uri) {
        return matches(HttpMethod.from(method), uri);
    }
104806
public function route($allRoute, $uriRoute, $httpMethod)
    {
        if(is_null($allRoute) || (is_array($allRoute) && !count($allRoute)) ) {
            throw new Exception("No routes. Define them at /app/Route/web.php");
        }
        $route = trim($uriRoute, '/ ');
        $array = $route === '' ? [] : explode('/', $route);
        $size = count($array);
        $allRoute = array_filter($allRoute, function($v) use ($size, $httpMethod) {
            if($v[0] != $httpMethod) {
                return false;
            }
            if($v[6] == $size) {
                return true;
            }
            if($v[8] == true && $v[7] <= $size && $v[6] >= $size) {
                return true;
            }
        });
        foreach ($allRoute as $route) {
            if ($this->match($route, $uriRoute)) {
                return $route;
            }
        }
        foreach ($allRoute as $route) {
            if ($this->match($route, $uriRoute, $httpMethod, true)) {
                return $route;
            }
        }
        // need a 404 route
        //$response->addHeader("404 Page Not Found")->send();
        throw new OutOfRangeException("No route matched the given URI : ".$uriRoute);
    }
1084264
public function matchRoute( string $method, string $uri )
  {
    # Make dispatcher
    $dispatcher = new \FastRoute\Dispatcher\GroupCountBased($this->routeCollector->getData());

    # Dispatch the requested METHOD and URI and see if a route matches
    $routeInfo = $dispatcher->dispatch($method, $uri);

    # Examine $RouteInfo response
    switch ($routeInfo[0])
    {
      # We found a route match
      case \FastRoute\Dispatcher::FOUND:
        # URLDecode each argument
        foreach ($routeInfo[2] as $idx=>$r)
        {
          $routeInfo[2][$idx] = \urldecode($r);
        }

        # Return the Handler + args
        return [
          'method'=>$method,
          'path'=>$uri,
          'handler'=>$routeInfo[1],
          'args'=>$routeInfo[2]
        ];
        break;

      # Nothing found
      case \FastRoute\Dispatcher::NOT_FOUND:
        return [];
        break;

      # This should never happen to us ...
      case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
        return [];
        break;

      # Default we return empty
      default:
        return [];
        break;
    }
  }
1017744
public RouteResult<T> route(HttpMethod method, String path) {
		return route(method, path, Collections.emptyMap());
	}
327693
protected function matchDynamicRoute($httpMethod, $path)
    {
        if ($routes = $this->collector->findDynamicRoutes($httpMethod, $path)) {
            // cache the parser reference
            $this->parser = $this->collector->getParser();
            // chunk routes for smaller regex groups using the Sturges' Formula
            foreach (array_chunk($routes, round(1 + 3.3 * log(count($routes))), true) as $chunk) {
                array_map([$this, "buildRoute"], $chunk);
                list($pattern, $map) = $this->buildGroup($chunk);

                if (!preg_match($pattern, $path, $matches)) {
                    continue;
                }

                /** @var Route $route */
                $route = $map[count($matches)];
                unset($matches[0]);

                $route->setParams(array_combine($route->getParams(), array_filter($matches)));

                return $route;
            }
        }

        return false;
    }