Matches the URI and route.

@param string $uri
@param string $routeUri

@return array|null
508100
private function match(string $uri, string $routeUri): ?array
    {
        if ($uri === $routeUri) {
            return [];
        }

        return $this->getArguments($uri, $routeUri);
    }
836956
protected function matchUrlDirectly($url)
    {
        foreach ($this->routes as $route) {
            if ($route->matchDirectly($url)) {
                return $route;
            }
        }
        return null;
    }
1056744
private function matchVariableVars(array $routeUri)
    {
        $this->vars = [];
        foreach ($routeUri as $index => $route) {
            if (!in_array($route, ['?', $this->uri[$index]])) {
                $this->vars = [];
                return; // match failed - no exact match, no variable match
            }
            if ($route === '?') { // found a variable
                $this->vars[] = $this->uri[$index];
            }
        }
    }
939225
public function parse(Uri $uri) :? array
	{
		// Get path without possible file
		$path = $uri->getPath();

		// Build route pattern
		$pattern = $this->buildRoutePattern();

		if (preg_match($pattern, $path, $matches) === 1) {

			$variables = [];
			$length = sizeof($matches);

			for ($i = 1; $i < $length; $i++) {
				$variables[$this->parameter[$i - 1]] = $matches[$i];
			}

			return $variables;
		}

		return null;
	}
1123747
public function execute($uri, $requestMethod)
    {
        foreach ($this->routes as $route) {
            if (true === $route->matches($uri, $requestMethod)) {
                return $route;
            }
        }
        return null;
    }
459974
public function GetRoute($uri = "")
	{
		$match = '';
		
		$qs = $uri ? $uri : (array_key_exists('QUERY_STRING', $_SERVER) ? $_SERVER['QUERY_STRING'] : '');
		$parsed = explode('&', $qs,2);
		$action = $parsed[0];
		
		if (strpos($action, '=') > -1 || !$action) {
			// the querystring is empty or the first param is a named param, which we ignore
			$match = $this->defaultAction;
		}
		else {
			// otherwise we have a route.  see if we have a match in the routemap, otherwise return the 'not found' route
			$method = RequestUtil::GetMethod();
			$route = $method.':'.$action;
			$match = array_key_exists($route, $this->routes) ? $this->routes[$route]['route'] : self::$ROUTE_NOT_FOUND;
		}
		
		return explode('.',$match,2);
	}
521968
public function analyseURI($uri)
    {
        $uriElements = '/' . implode('/', $this->getURIElements());
        if ($uri == $uriElements) {
            $uri = '';
        } elseif (strpos($uri, $uriElements) === 0) {
            $uri = mb_substr($uri, mb_strlen($uriElements));
        }

        return $uri;
    }
1217686
public static function getAbsoluteUri(string $uri = null) : string
    {
        $uri = new self($uri);

        return $uri->get(false);
    }
1007029
public function resolve($uri, $baseUri = null)
    {
        $components = $this->parse($uri);
        $path = $components['path'];

        if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
            return $uri;
        }

        $baseComponents = $this->parse($baseUri);
        $basePath = $baseComponents['path'];

        $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);

        return $this->generate($baseComponents);
    }
1352147
public function checkUri($uris)
    {
        if (!$this->request) {
            return false;
        }

        foreach ((array)$uris as $uri) {
            if ($this->uri == $uri) {
                return true;
            }
        }

        return false;
    }
708482
private static function route($uri) {
		$result = $uri;
		$routes = \Application::get('routes');
		if (empty($routes)) $routes = [];
		$extra_routes = \Object\ACL\Resources::getStatic('routes');
		if (!empty($extra_routes)) {
			$routes = array_merge($routes, $extra_routes);
		}
		if (!empty($routes)) {
			foreach ($routes as $v) {
				$regex = '#^' . $v['regex'] . '#i';
				if (preg_match($regex, $result, $values)) {
					$result = str_replace($v['regex'], $v['new'], $result);
				}
			}
		}
		return $result;
	}
1374030
private function getArguments(string $uri, string $routeUri): ?array
    {
        if (preg_match_all('/({[a-z]+:)/i', $routeUri, $matches)) {
            $regex = str_replace('/', '\/',
                str_replace('}', ')',
                    preg_replace('/{([a-z]+):/i', '(?<$1>', $routeUri)
                )
            );

            return $this->matchUri($regex, $uri);
        }

        return null;
    }
336240
private void giveMatch(final String uri, List<Route> routes) {
        routes.stream().sorted((o1, o2) -> {
            if (o2.getPath().equals(uri)) {
                return o2.getPath().indexOf(uri);
            }
            return -1;
        });
    }
958741
protected function extractOptionalParameters($uri)
    {
        preg_match_all('/\{(\w+?)\?\}/', $uri, $matches);

        return isset($matches[1]) ? array_fill_keys($matches[1], null) : array();
    }
1294863
private function setUri($uri)
    {
        $this->uri = $uri;

        preg_match_all('/({[^}]+})/', $this->uri, $matches);
        $this->params = $matches[0];

        return $this;
    }
1130421
public function match($resourceUri)
    {
        $paramNames = $this->getParamNames();

        $pattern =  $this->getPattern();

        if (preg_match('/\[:options\]/', $pattern)) {
            $exp = explode('[:options]', $pattern);
            $estatico = $exp[0];
            $estaticoDinamico = explode($estatico, $resourceUri);
            if (count($estaticoDinamico) == 2) {
                $estaticoUrl = explode($estaticoDinamico[1], $resourceUri);
                $estaticoUrl = $estaticoUrl[0];

                if ($estaticoUrl == $estatico){
                    //estou em uma rota dinamica valida
                    $dinamico = $estaticoDinamico[1];
                    $this->options = explode('/', $dinamico);
                    return true;
                }
            } else {
                return false;
            }
        } else {
            $patternAsRegex = preg_replace_callback('@:[\w]+@', [$this, 'convertToRegex'], $this->pattern);
            if (substr($this->pattern, -1) === '/') {
                $patternAsRegex = $patternAsRegex . '?';
            }
            $patternAsRegex = '@^' . $patternAsRegex . '$@';

            if (preg_match($patternAsRegex, $resourceUri, $paramValues)) {
                array_shift($paramValues);
                
                if (count($paramValues) > 0) {
                    foreach ($paramNames as $index => $value) {
                        $this->params[substr($value, 1)] = urldecode($paramValues[$index]);
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    }
1085749
public static function parse(string $uri): Uri
    {
        preg_match(static::URI_PATTERN, $uri, $matches);

        $components = static::componentsFromMatches($matches);
        $scheme = $components['scheme'];
        $authority = $components['authority'];
        $path = $components['path'];
        $query = $components['query'];
        $fragment = $components['fragment'];

        return new static($path, $scheme, $authority, $query, $fragment);
    }