match
Match a request URL to a route.

@param string $pathinfo
@return array $routes

@throws RoutingException
770831
public function match($pathinfo)
    {
        $routes = array();
        $this->debug(sprintf('match: Matching %s', $pathinfo));

        foreach ($this->matchers as $matcher) {
            try {
                $routes = $matcher->match($pathinfo);
                break;
            } catch (ResourceNotFoundException $e) {
            } catch (MethodNotAllowedException $e) {
            }
        }

        if (!isset($routes['_route']) || !isset($routes['_controller'])) {
            $mesg = 'match: No Routes Found.';
            $this->alert($mesg);
            throw new RoutingException($mesg);
        }

        $this->debug(sprintf('match: Route matched %s', $routes['_route']));

        return($routes);
    }
301100
public function match($pathinfo)
    {
        $urlMatcher = new UrlMatcher(
            $this->getRouteCollection(),
            $this->getContext()
        );

        $result = $urlMatcher->match($pathinfo);
        if (!empty($result)) {
            // Remap locale for front-end requests
            if ($this->isMultiDomainHost() &&
                $this->isMultiLanguage() &&
                !$result['preview']
            ) {
                $localeMap = $this->getLocaleMap();
                $locale = $result['_locale'];
                $result['_locale'] = $localeMap[$locale];
            }

            $nodeTranslation = $this->getNodeTranslation($result);
            if (is_null($nodeTranslation)) {
                throw new ResourceNotFoundException(
                    'No page found for slug ' . $pathinfo
                );
            }
            $result['_nodeTranslation'] = $nodeTranslation;
        }

        return $result;
    }
1067976
public function match($path, $verb)
    {
        foreach ($this->routes as $route) {
            $route->build();
            if (false !== ($routeParams = $this->matcher->match($route->build(), $path, $verb))) {
                return [$route, $routeParams];
            }
        }
        return false;
    }
768412
public function match($pathInfo)
    {
        if ($ret = $this->matchCollection($pathInfo, $this->routesCopy)) {
            return $ret;
        }

        return false;
    }
1196251
protected function matchRoute($pathinfo, $name, BaseRoute $route) {
		$compiledRoute = $route->compile();

		// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
		if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
			return null;
		}

		if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
			return null;
		}

		$hostMatches = array();
		if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
			return null;
		}

		// check HTTP method requirement
		if ($req = $route->getRequirement('_method')) {
			// HEAD and GET are equivalent as per RFC
			if ('HEAD' === $method = $this->context->getMethod()) {
				$method = 'GET';
			}

			if (!in_array($method, $req = explode('|', strtoupper($req)))) {
				$this->allow = array_merge($this->allow, $req);

				return null;
			}
		}

		$status = $this->handleRouteRequirements($pathinfo, $name, $route);

		if (self::ROUTE_MATCH === $status[0]) {
			return $status[1];
		}

		if (self::REQUIREMENT_MISMATCH === $status[0]) {
			return null;
		}

		$attrs = $this->getAttributes($route, $name, array_replace($matches, $hostMatches));

		if($route instanceof Route) {
			foreach($route->getMatchCallbacks() as $callback) {
				$ret = call_user_func($callback, $attrs);
				if($ret === false) {
					return null;
				}
				if(is_array($ret)) {
					$attrs = $ret;
				}
			}
		}

		return $attrs;

	}
350638
private function getCacheItemMatch($pathinfo)
    {
        /** @type RequestContext $c */
        $c   = $this->getContext();
        $key = sprintf('%s__%s__%s__%s', $c->getHost(), $pathinfo, $c->getMethod(), $c->getQueryString());

        return $this->getCacheItemFromKey($key, 'match');
    }
272686
public function parsePathInfo(UrlManager $urlManager, $pathInfo)
    {
        $pathInfo .= '/';
        if (preg_match($this->pattern, $pathInfo, $ms)) {
            foreach ($this->defaultParams as $name => $value) {
                if (!isset($_GET[$name])) {
                    $_REQUEST[$name] = $_GET[$name] = $value;
                }
            }
            $tr = [];
            foreach ($ms as $key => $value) {
                if (isset($this->references[$key])) { // 路由
                    $tr[$this->references[$key]] = $value;
                } elseif (isset($this->params[$key])) { // GET 参数
                    $_REQUEST[$key] = $_GET[$key] = $value;
                }
            }
            if ($pathInfo !== $ms[0]) { // 解析传统的 $_GET 参数
                $urlManager->parsePathInfo(ltrim(substr($pathInfo, strlen($ms[0])), '/'));
            }
            if ($this->routePattern !== null) {
                // 替换找到对应的action
                return strtr($this->route, $tr);
            } else {
                return $this->route;
            }
        }
        return false;
    }
1081522
private function getMatchRoute(string $method, string $url)
    {
        $parsedRoutes = $this->parseRoutes($this->routeCollection);
        foreach ($parsedRoutes as $singleParsedRoute) {
            list($routeRegex, $route) = $singleParsedRoute;
            $matchedParameters        = $this->routeMatch($routeRegex, $url);

            if ($matchedParameters !== false) {
                $routeMethod = $route->getMethod();
                if ($routeMethod === $method || $routeMethod === Method::ANY) {
                    $route->setParameters($matchedParameters);

                    return $route;
                }
            }
        }

        return false;
    }
1328009
public function match(ServerRequestInterface $request) : RouterMatch
    {
        $path = $request->getUri()->getPath();
        $syContext = new RequestContext('/');
        $syMatcher = new UrlMatcher($this->syRouteCollection, $syContext);
        try {
            $params = $syMatcher->match($path);
        } catch (\Throwable $e) {
            throw new HttpException(404, "No route matched for path $path",
                null, $e);
        }
        
        $matchedRouteName = $params['_route'];
        unset($params['_route']);
        $route = $this->routeProvider->getRouteFromName($matchedRouteName);
        $routerMatch = new RouterMatch($route, $params);
        return $routerMatch;
    }
161085
private function matchRoute(ServerRequestInterface $request) : RouterMatch
    {
        $this->eventDispatcher->dispatch(new EventBeforeAppMatchingRoute($request));
        try {
            $routerMatch = $this->router->match($request);
        } catch (\Throwable $e) {
            $statusCode = 404;
            $message = "$statusCode: Router could not match request path {$request->getUri()->getPath()}";
            throw new HttpException($statusCode, $message, null, $e);
        }
        $this->eventDispatcher->dispatch(new EventAfterAppMatchingRoute($request, $routerMatch));
        return $routerMatch;
    }
773083
private function matchRoute($expectedRoute) {
		$params = [];

		// create the regex that matches paths against the route
		$expectedRouteRegex = $this->createRouteRegex($expectedRoute, $params);

		// if the route regex matches the current request path
		if (preg_match($expectedRouteRegex, $this->route, $matches)) {
			if (count($matches) > 1) {
				// remove the first match (which is the full route match)
				array_shift($matches);

				// use the extracted parameters as the arguments' keys and the matches as the arguments' values
				return array_combine($params, $matches);
			}
			else {
				return [];
			}
		}
		// if the route regex does not match the current request path
		else {
			return null;
		}
	}
1354466
protected function loadAnnotationRoute($pathinfo)
    {
        @list($empty, $pack, $controller, $method) = explode('/', $pathinfo);

        if (!isset($this->packs[$pack])) {
            return;
        }

        if (isset($this->map[$controller])) {
            $controller = $this->map[$controller];
        }

        $controller = $this->underscoreToCamelCase($controller, true);

        $fullClassName = $this->packs[$pack]->getNameSpace().'\\Controller\\'.$controller;

        if (class_exists($fullClassName)) {
            $this->resolver->resolveController($fullClassName, $this->packs[$pack]);
        }
    }
926964
public function isMatch($pathInfo)
	{
		$this->compile();

		$pathInfo = trim($pathInfo, '/');

		if (!preg_match($this->pattern, $pathInfo, $paramValues))
		{
			return false;
		}

		foreach ($this->paramNames as $name)
		{
			$this->params[$name] = isset($paramValues[$name]) ? urldecode($paramValues[$name]) : null;
		}

        return true;
	}
1236759
public function getMatchingRoute($routes, Request $request)
    {
        foreach ($routes as $matchingRoute) {
            if ($matchingRoute->matches($request)) {
                return $matchingRoute;
            }
        }

        return null;
    }
374359
public function match(ServerRequestInterface $request)
    {
        $basePathLength = strlen($this->baseUri['path']);

        return RouteCollectionMatcher::matchRouteCollection(
            $this->routeCollection,
            $request,
            $basePathLength,
            []
        ) ?: MatchResult::fromMatchFailure();
    }
888977
protected function _routeMatch($matches)
    {
        if (isset($this->_tmpMatches[$matches[1]])) {
            return $this->_tmpMatches[$matches[1]];
        }
        if (isset($this->_tmpDefault[$this->_tmpKey])) {
            return $this->_tmpDefault[$this->_tmpKey];
        }
        throw new \Mmi\Mvc\MvcException('Router failed due to invalid route definition - no default param for key: ' . $this->_tmpKey);
    }
392616
private function getUri($pathinfo, $urlType = RouteCollection::DEFAULT_URL)
    {
        return $this->routeCollection->getUri($pathinfo, null, null, $urlType);
    }