Match routes.

@param string $route
@param string $method
@param array  $options

@return  Route|false
556846
public function match($route, $method = 'GET', $options = [])
    {
        $this->count = 0;

        foreach ($this->routes as $routeItem) {
            $this->count++;

            if (!$this->matchOptions($routeItem, $method, $options)) {
                continue;
            }

            if ($this->matchRoute($route, $routeItem)) {
                return $routeItem;
            }
        }

        return false;
    }
580994
protected function matchAgainstRoutes(array $routes, $request, $includingMethod = true)
    {
        [$fallbacks, $routes] = collect($routes)->partition(function ($route) {
            return $route->isFallback;
        });

        return $routes->merge($fallbacks)->first(function ($value) use ($request, $includingMethod) {
            return $value->matches($request, $includingMethod);
        });
    }
407918
public function findFirstMatchingRoute($alternative=false) {
		/* @var ControllerRoute $route */
		foreach( $this->getRoutes() as $methodRoutes ) {
			if( !isset($methodRoutes[$this->method]) ) { continue; }
			/* @var $route HTTPRoute */
			$route = $methodRoutes[$this->method];
			$values = null;
			if( $route->isMatchingRequest($this, $values, $alternative) ) {
				$this->pathValues = (object) $values;
				return $route;
			}
		}
		return null;
	}
1249794
public function getRequest($method, $url, array $options = [])
    {
        return $this->createRequest($method, $url, null, $options);
    }
883865
protected function _doRequest($method, $uri, $options)
    {
        return $this->httpClient->request($method, $uri, $options);
    }
423704
public function match($uri = null, $method = null)
    {
        $context = $this->_context;

        $uri = $uri ?: $this->getRewriteUri();

        if ($method === null) {
            $method = $this->request->getServer('REQUEST_METHOD');
        }

        $context->controller = null;
        $context->action = null;
        $context->params = [];

        $context->matched = false;

        if ($this->_prefix) {
            if (strpos($uri, $this->_prefix) === 0) {
                $handledUri = substr($uri, strlen($this->_prefix)) ?: '/';
            } else {
                $handledUri = false;
            }
        } else {
            $handledUri = $uri;
        }

        $area = null;
        $routes = $this->_simple_routes;
        if ($handledUri === false) {
            $parts = false;
        } elseif (isset($routes[$method][$handledUri])) {
            $parts = $routes[$method][$handledUri]->match($handledUri, $method);
        } elseif (isset($routes[''][$handledUri])) {
            $parts = $routes[''][$handledUri]->match($handledUri, $method);
        } else {
            $parts = false;
            $routes = $this->_regex_routes;
            for ($i = count($routes) - 1; $i >= 0; $i--) {
                $route = $routes[$i];
                if (($parts = $route->match($handledUri, $method)) !== false) {
                    if ($handledUri !== '/' && $this->_areas) {
                        if (($pos = strpos($handledUri, '/', 1)) === false) {
                            $area = Text::camelize(substr($handledUri, 1));
                        } else {
                            $area = Text::camelize(substr($handledUri, 1, $pos - 1));
                        }

                        if (!in_array($area, $this->_areas, true)) {
                            $area = null;
                        }
                    }
                    break;
                }
            }

            if ($parts === false) {
                if ($handledUri !== '/' && $this->_areas) {
                    if (($pos = strpos($handledUri, '/', 1)) !== false) {
                        $area = Text::camelize(substr($handledUri, 1, $pos - 1));
                        if (in_array($area, $this->_areas, true)) {
                            $handledUri = substr($handledUri, $pos);
                        } else {
                            $area = null;
                        }
                    } else {
                        $area = Text::camelize(substr($handledUri, 1));
                        if (in_array($area, $this->_areas, true)) {
                            $handledUri = '/';
                        } else {
                            $area = null;
                        }
                    }
                }

                $handledUri = $handledUri === '/' ? '/' : rtrim($handledUri, '/');
                $parts = $this->_default_route->match($handledUri, $method);
            }
        }

        if ($parts === false) {
            return false;
        }

        $context->matched = true;

        if ($area) {
            $context->area = $area;
        } elseif (isset($parts['area'])) {
            $context->area = $parts['area'];
        }

        $context->controller = $parts['controller'];
        $context->action = $parts['action'];
        $context->params = isset($parts['params']) ? $parts['params'] : [];

        return $context;
    }
1337724
protected function matchSimpleRouting($route, $method, MainRouter $router)
    {
        $route      = explode('/', $route);
        $controller = array_pop($route);
        $class      = StringNormalise::toClassNamespace(
            sprintf(
                '%s\Controller\%s\%s',
                implode($route, '\\'),
                ucfirst($controller),
                $router->fetchControllerSuffix($method)
            )
        );

        // Find package
        $ns = implode('\\', array_map('ucfirst', $route)) . '\\' . ucfirst(end($route)) . 'Package';

        $resolver = $this->getPackageResolver();

        // If package not found but class exists, try create one
        if (!$resolver->getAlias($ns) && class_exists($ns)) {
            $resolver->addPackage(end($route), new $ns());
        }

        // Get package, if not exists, return DefaultPackage
        $package = $resolver->resolvePackage($resolver->getAlias($ns));

        $packageName = $package ? $package->getName() : implode('.', $route);

        if (!class_exists($class)) {
            return false;
        }

        $matched = new Route($packageName . '@' . $controller, implode($route, '/'));

        $matched->setExtraValues(
            [
                'controller' => $class,
            ]
        );

        return $matched;
    }
888564
public function match( $method, $path, callable $callback ) {
        $route = new Route( mb_strtoupper( $method ), $path, $callback );
        $this->_routes[] = $route;
        return $route;
    }
1276675
public function matches(Route $route, Request $request)
    {
        /** @var \LaraPress\Routing\Route $route */
        return $route->wordpressConditional() == null || call_user_func($route->wordpressConditional(), $route->uri());
    }
361756
public function map($method, $route, $action)
    {
        return $this->getRouter()->map($method, $route, $this->bindClosureToInstance($action, $this));
    }
293125
public function match(string $route): array
    {
        if (!isset($this->routes[$route])) {
            return [];
        }

        return $this->routes[$route];
    }
1029464
public function match($uri, $method = 'GET')
    {
        $matches = [];

        if ($this->_method !== null && $this->_method !== $method && $this->_method !== 'REST') {
            return false;
        }

        if ($this->_compiledPattern[0] !== '#') {
            if ($this->_compiledPattern === $uri) {
                return $this->_paths;
            } else {
                return false;
            }
        } else {
            $r = preg_match($this->_compiledPattern, $uri, $matches);
            if ($r === false) {
                throw new InvalidFormatException([
                    '`:compiled` pcre pattern is invalid for `:pattern`',
                    'compiled' => $this->_compiledPattern,
                    'pattern' => $this->_pattern
                ]);
            } elseif ($r === 1) {
                $parts = $this->_paths;

                foreach ($matches as $k => $v) {
                    if (is_string($k)) {
                        $parts[$k] = $v;
                    }
                }

                if ($this->_method === 'REST') {
                    if (isset($matches['params'])) {
                        $methodAction = ['GET' => 'detail', 'POST' => 'update', 'PUT' => 'update', 'DELETE' => 'delete'];
                    } else {
                        $methodAction = ['GET' => 'index', 'POST' => 'create'];
                    }
                    if (isset($methodAction[$method])) {
                        $parts['action'] = $methodAction[$method];
                    } else {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }

        if (isset($parts['controller']) && $parts['controller'] === '') {
            unset($parts['controller']);
        }

        if (isset($parts['action']) && $parts['action'] === '') {
            unset($parts['action']);
        }

        $r = [];
        $r['controller'] = isset($parts['controller']) ? $parts['controller'] : 'index';
        if (isset($parts['area'])) {
            $r['area'] = $parts['area'];
        }

        $r['action'] = isset($parts['action']) ? $parts['action'] : 'index';
        $params = isset($parts['params']) ? $parts['params'] : '';

        unset($parts['area'], $parts['controller'], $parts['action'], $parts['params']);
        if ($params) {
            $parts[0] = $params;
        }
        $r['params'] = $parts;

        return $r;
    }
1293498
public function findRoute($method, $uri)
	{
		$this->method = $method;
		if ($this->routesTree === null) {
			$this->routesTree = $this->parseRoutes($this->rawRoutes);
		}

		$search = $this->normalize($uri);

		$node   = $this->routesTree;
		$params = [];

		//loop every segment in request url, compare it, collect parameters names and values
		foreach ($search as $key => $v) {

			if (isset($node[$v["use"]])) {
				$node = $node[$v["use"]];
			} else if (isset($node["*"])) {

				$subnode = $node["*"];
				if (($definitions = $this->rawRoutes[$subnode["routeName"]]["definitions"]) !== null) {
					if (isset($definitions[$subnode["name"]])) {
						$definition = $definitions[$subnode["name"]];
						$regex = ($definition[0] === "(") ? $definition : $this->getMatchType($definition, "(.*)");

						if ($regex === "(.*)") {
							break;
						} else {
							if (!preg_match($regex, $v['name'])) {
								throw new RouteNotFoundException("Route for uri: {$uri} was not found");
							}
						}
					}
				}
				// This sets node to continue
				$node = $subnode;
				$params[$subnode["name"]] = $v["name"];

			} else if (isset($node["?"])) {
				$node = $node["?"];

				if (($definitions = $this->rawRoutes[$method][$node["routeName"]]["definitions"]) !== null) {
					if (isset($definitions[$node["name"]])) {
						$definition = $definitions[$node["name"]];
						$regex = ($definition[0] === "(") ? $definition : $this->getMatchType($definition, "any");

						if ($regex === "(.*)") {
							$c = count($search);
							for ($i=$key; $i < $c; $i++) {
								$b[] = $search[$i]["use"];
							}
							$params[$node["name"]] = $b;
							break;
						} else {
							if (!preg_match($regex, $v['name'])) {
								continue;
							}
							$node = $node["?"];
							$params[$node["name"]] = $v["name"];
						}
					}
				}

				$params[$node["name"]] = $v["name"];
			} else {
				throw new RouteNotFoundException("Route for uri: {$uri} was not found");
			}

		}

		// Check for route with optional parameters that are not in request url until valid action is found
		// This make tree to go to last key
		while (!isset($node["exec"]) && isset($node["?"])) {
			$node = $node["?"];
		}

		if (isset($node["exec"])) {
			if (!isset($node["exec"]["method"][$method])
				&& !isset($node["exec"]["method"]["any"])
			) {
				throw new MethodNotAllowedException("Method: {$method} is not allowed for this route");
			}

			$Route = $node["exec"]["method"][$method];
			$Route->params = $params;
			if ($a = is_array($Route->action) || is_string($Route->action)) {
				if ($a) {
					$Route->action = [$Route->namespace.$Route->action[0], $Route->action[1]];
				} else {
					$Route->action = $Route->namespace.$Route->action;
				}
			}
			return $Route;
		}
		throw new RouteNotFoundException("Route for uri: {$uri} was not found");
	}
1070677
private function matchRoutes(string $method, array $segments): array
    {
        $staticIds = $this->provider->getRoutesByStaticPath(implode('/', $segments));

        if ($staticIds !== []) {
            $routes = $this->getMatchingRoutes($staticIds, $method, $segments);

            if ($routes !== []) {
                return $routes;
            }
        }

        if ($segments === []) {
            return [];
        }

        $matchedIds = $this->getDynamicRouteIds($segments);
        return $this->getMatchingRoutes($matchedIds, $method, $segments);
    }
956742
public function findRoute(string $method, string $url, string $host = null): bool
    {
        $this->method = $method;
        $this->url = $this->removeQueryFromUrl($url);
        $this->host = $host;

        return $this->find();
    }
786900
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;
    }
611746
public function getRoutesByMethod($method)
	{
		return ($this->routesByMethod && isset($this->routesByMethod[$method])) ? $this->routesByMethod[$method] : array();
	}