Extracts and matches the parameters with their defined names.

@param               $matches
@param CompiledRoute $compiledRoute

@return array
173356
private function extractParameters($matches, CompiledRoute $compiledRoute)
    {
        $params = [];
        foreach ($compiledRoute->getVariables() as $index => $var) {
            $params[$var['name']] = $matches[($index + 1)][0];
        }

        return $params;
    }
661591
private function getNamedPatterns($matches)
    {
        foreach ($matches as $key => $value) {
            if (!is_string($key) || strlen($value) < 1) {
                unset($matches[$key]);
            }
        }

        return $matches;
    }
1300368
protected function computeMissingRouteParameters(Route $route, array $parameters): array
    {
        $compiledRoute = $route->compile();
        $variables = array_flip($compiledRoute->getVariables());
        $mergedParams = array_replace($route->getDefaults(), $this->router->getContext()->getParameters(), $parameters);

        return array_flip(array_diff_key($variables, $mergedParams));
    }
797516
protected function fixMatches($matches)/*# : array */
    {
        // remove numeric keys and empty group match
        foreach ($matches as $idx => $val) {
            if (is_int($idx) || '' === $val) {
                unset($matches[$idx]);
            }
        }

        // get route key/name
        $routeKey = array_keys($matches)[0];
        $len = strlen($routeKey);

        // fix remainging match key
        $res = [];
        foreach ($matches as $key => $val) {
            if ($key != $routeKey) {
                $res[substr($key, 0, -$len)] = $val;
            }
        }

        // debug
        $this->debug(Message::get(
            Message::DEBUG_MATCH_REGEX,
            $this->regex[$routeKey]
        ));

        return [ $routeKey, $res ];
    }
121757
private function assembleReplaceCallback(array $matches)
    {
        if (!isset($this->assembleParams[$matches[1]])) {
            throw new RuntimeException($this->translate(
                'Assemble param "{name}" does not exist.',
                ['name' => $matches[1]]
            ));
        }

        return $this->assembleParams[$matches[1]];
    }
657363
public function match(string $path, string $method = 'GET'): array
    {
        // if enable 'matchAll'
        if ($matchAll = $this->matchAll) {
            if (\is_string($matchAll) && $matchAll{0} === '/') {
                $path = $matchAll;
            } elseif (\is_callable($matchAll)) {
                return [self::FOUND, $path, [
                    'handler' => $matchAll,
                ]];
            }
        }

        $path = $this->formatUriPath($path, $this->ignoreLastSlash);
        $method = strtoupper($method);

        // find in route caches.
        if ($this->cacheRoutes && isset($this->cacheRoutes[$path][$method])) {
            return [self::FOUND, $path, $this->cacheRoutes[$path][$method]];
        }

        // is a static route path
        if ($this->staticRoutes && ($routeInfo = $this->findInStaticRoutes($path, $method))) {
            return [self::FOUND, $path, $routeInfo];
        }

        $first = null;
        $allowedMethods = [];

        // eg '/article/12'
        if ($pos = strpos($path, '/', 1)) {
            $first = substr($path, 1, $pos - 1);
        }

        // is a regular dynamic route(the first node is 1th level index key).
        if ($first && isset($this->regularRoutes[$first])) {
            $result = $this->findInRegularRoutes($this->regularRoutes[$first], $path, $method);

            if ($result[0] === self::FOUND) {
                return $result;
            }

            $allowedMethods = $result[1];
        }

        // is a irregular dynamic route
        if (isset($this->vagueRoutes[$method])) {
            $result = $this->findInVagueRoutes($this->vagueRoutes[$method], $path, $method);

            if ($result[0] === self::FOUND) {
                return $result;
            }
        }

        // For HEAD requests, attempt fallback to GET
        if ($method === 'HEAD') {
            if (isset($this->cacheRoutes[$path]['GET'])) {
                return [self::FOUND, $path, $this->cacheRoutes[$path]['GET']];
            }

            if ($routeInfo = $this->findInStaticRoutes($path, 'GET')) {
                return [self::FOUND, $path, $routeInfo];
            }

            if ($first && isset($this->regularRoutes[$first])) {
                $result = $this->findInRegularRoutes($this->regularRoutes[$first], $path, 'GET');

                if ($result[0] === self::FOUND) {
                    return $result;
                }
            }

            if (isset($this->vagueRoutes['GET'])) {
                $result = $this->findInVagueRoutes($this->vagueRoutes['GET'], $path, 'GET');

                if ($result[0] === self::FOUND) {
                    return $result;
                }
            }
        }

        // If nothing else matches, try fallback routes. $router->any('*', 'handler');
        if ($this->staticRoutes && ($routeInfo = $this->findInStaticRoutes('/*', $method))) {
            return [self::FOUND, $path, $routeInfo];
        }

        if ($this->notAllowedAsNotFound) {
            return [self::NOT_FOUND, $path, null];
        }

        // collect allowed methods from: staticRoutes, vagueRoutes OR return not found.
        return $this->findAllowedMethods($path, $method, $allowedMethods);
    }
1262431
private function match(string $url, Route $route) : array
    {
        $regexp = $this->routeRegexp($route);

        if (preg_match_all('`^' . $regexp . '$`', $url, $matches, PREG_SET_ORDER)) {
            // remove all numeric matches
            $matches = array_diff_key($matches[0], range(0, count($matches[0])));

            // control query string
            if ($route->getUserInputs()) {
                foreach ($route->getUserInputs() as $querystring) {
                    $method = self::request()->getMethod() == 'POST' ? 'getPostOrQuery' : 'getQuery';
                    $value = self::request()->$method($querystring->getName(), $querystring->getType());

                    if (is_null($value) && $querystring->isMandatory()) {
                        return [false, null, $regexp];
                    }

                    if (!is_null($value)) {
                        $matches[$querystring->getName()] = $value;
                    }
                }
            }

            // control conditions
            if ($route->getConditions()) {
                foreach ($route->getConditions() as $condition) {
                    if (!$condition($matches)) {
                        return [false, null, $regexp];
                    }
                }
            }

            return [true, $matches, $regexp];
        }

        return [false, null, $regexp];
    }
442524
protected function fixMatches($matches)/*# : array */
    {
        $this->removeNumericAndEmpty($matches);

        // get route key/name
        $routeName = array_keys($matches)[0];
        $len = strlen($routeName);
        $res = [];
        foreach ($matches as $key => $val) {
            if ($key != $routeName) {
                $res[substr($key, 0, -$len)] = $val;
            }
        }

        $this->debug(Message::get(
            Message::RTE_PARSER_MATCH,
            $routeName,
            $this->regex[$routeName]
        ));

        return [$routeName, $res];
    }
580580
private function detectRouteForWithIdentifierPattern(array $matches): ?Route
    {
        $actions = [
            'GET' => 'singleAction',
            'PUT' => 'editAction',
            'DELETE' => 'destroyAction'
        ];

        if (!isset($actions[$this->request->getMethod()])) {
            return null;
        }

        $controllerName = implode('', array_map('ucfirst', explode('-', $matches['controller'])));
        $controller = $this->configuration->getControllerNamespace() . $controllerName . 'Controller';

        return (new Route())
            ->setController($controller)
            ->setAction($actions[$this->request->getMethod()])
            ->setActionParams([$matches['id']]);
    }
509019
private function getRouteVars(RouteContextInterface $context, array $parameters)
    {
        return array_merge(
            array_combine(array_values($v = $context->getVars()), array_fill(1, count($v), null)),
            $parameters
        );
    }
712107
private function routeMatch(string $routeRegex, string $route)
    {
        $matches = [];
        if (preg_match($routeRegex, $route, $matches)) {
            unset($matches[0]);

            return array_values($matches);
        }

        return false;
    }
1078845
protected function getVariables($matches)
    {
        $variables = array();
        
        if (!is_array($matches)) {
            return $variables;
        }
        
        array_shift($matches);
        
        foreach ($matches as $path) {
            $variables = array_merge($variables, explode('/', $path));
        }
        
        foreach ($variables as $i => $variable) {
            if (!$variable) {
                unset($variables[$i]);
            }
        }
        
        return array_values($variables);
    }
293125
public function match(string $route): array
    {
        if (!isset($this->routes[$route])) {
            return [];
        }

        return $this->routes[$route];
    }
152799
private function filterHref($matches) {

		static $script;
		static $observeRewrite;

		if(is_null($script)) {
			$script = trim(Request::createFromGlobals()->getScriptName(), '/');
		}

		if(is_null($observeRewrite)) {
            $observeRewrite = Application::getInstance()->getRouter()->getServerSideRewrite();
		}

		$matches[4] = html_entity_decode($matches[4]);

		$uriParts = [];

		if($observeRewrite) {
			if($script !== 'index.php') {
				$uriParts[] = basename($script, '.php');
			}
		}
		else {
			$uriParts[] = $script;
		}

		if($matches[3] !== '') {
			$uriParts[] = $matches[3];
		}

		$uri = implode('/', $uriParts) . $matches[4];

		return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";
	}
414735
private function getMatchStringParameterIndices($matchString, $pattern)
    {
        $indices = [];

        foreach ($pattern as $part) {
            if (!$this->isTokenPatternPart($part)) {
                $offset = 0;

                foreach ($indices as $currentIndex) {
                    $prefix = $currentIndex['prefix'];

                    if ($prefix == $part || substr_count($prefix, $part) || substr_count($part, $prefix)) {
                        $offset = $currentIndex['index'];
                    }
                }

                $indices[] = [
                    'prefix' => $part,
                    'index' => strpos($matchString, $part, $offset) + strlen($part)
                ];
            }
        }

        return $indices;
    }
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);
    }
628935
public function parameters($request)
    {
        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        $parameters = $this->bindPathParameters($request);

        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        if (! is_null($this->route->compiled->getHostRegex())) {
            $parameters = $this->bindHostParameters(
                $request, $parameters
            );
        }

        return $this->replaceDefaults($parameters);
    }