Parse the path info to parameter set

@param  string $pathInfo    The path info to match
@param  string|null $method The request method to match, maybe GET, POST, etc
@return array
507924
public function matchParamSet($pathInfo, $method = 'GET')
    {
        $params = $this->match($pathInfo, $method);
        $restParams = $this->matchRestParamSet($pathInfo, $method);
        return $params ? array_merge(array($params), $restParams) : $restParams;
    }
751956
public function match($pathinfo)
    {
        // Template router only accepts GET or HEAD requests
        if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
            throw new MethodNotAllowedException(array('GET', 'HEAD'));
        }

        $return = null;

        // Resolve the template and make sure it's routable
        $template = $this->resolver->resolveTemplate(rawurldecode($pathinfo));

        if ((false !== $template) && $this->isRoutableTemplate($template)) {
            $return = array(
                '_controller' => $this->controller,
                '_route' => $template->getRenderName(),
                'template' => $template,
            );
        }

        if ($return) {
            return($return);
        } else {
            throw new ResourceNotFoundException();
        }
    }
690892
public static function parseParameters(Method $method) : array
	{
		$taskName = NULL;
		if ($method->hasAnnotation(Parameters::TASK)) {
			$className = $method->getDeclaringClass()->getName();
			$methodName = $method->getName();
			$taskName = $className . ' - ' . $methodName;
		}

		$taskAnnotation = $method->getAnnotation(Parameters::TASK);

		$parameters = [
			static::TASK => is_string($taskAnnotation)
				? Parser::parseName($taskAnnotation)
				: $taskName,
			static::PERIOD => $method->hasAnnotation(Parameters::PERIOD)
				? Parser::parsePeriod((string) $method->getAnnotation(Parameters::PERIOD))
				: NULL,
			static::DAYS => $method->hasAnnotation(Parameters::DAYS)
				? Parser::parseDays((string) $method->getAnnotation(Parameters::DAYS))
				: NULL,
			static::TIME => $method->hasAnnotation(Parameters::TIME)
				? Parser::parseTimes((string) $method->getAnnotation(Parameters::TIME))
				: NULL,
		];

		return $parameters;
	}
830547
private function matchTreeForMethods(array $methods, string $path)
    {
        if ($result = $this->matchKeyValue($path, $methods)) {
            return $result;
        }

        $nodesPointer = &$this->nodesTree;
        $chars = \str_split($path);

        while (true) {
            $candidates = \array_merge(
                $nodesPointer['regex'] ?? [],
                $nodesPointer['all'] ?? []
            );

            foreach ($candidates as list($route, $handler, $params, $method)) {
                if (!\in_array($method, $methods, true)) {
                    continue;
                }
                /** @var PatternRoute $route */
                if ($route->match($path, $queryParams)) {
                    return new InternalRoute($handler, \array_replace($params, $queryParams));
                }
            }

            $char = \array_shift($chars);
            if (!\is_string($char) || !isset($nodesPointer[$char])) {
                break;
            }
            $nodesPointer = &$nodesPointer[$char];
        }

        return null;
    }
815527
public function match($method, $url)
	{
		$params = array();

		foreach ($this->routes as $name => $route)
		{
			if ($route->isMatch($method, $url))
			{
				$params = $route->getMatchedParams();
				break;
			}
		}

		return $params;
	}
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;
    }
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]);
        }
    }
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');
    }
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);
    }
1217946
public function method($method, $path = null)
	{
		if($path !== null)
			$this->setPath($path);

		return $this->setMethod($method);
	}
294971
public function matchRestParamSet($path, $method = 'GET')
    {
        $rootCtrl = '';
        $params = array();
        $routes = array();

        // Split out format
        if (strpos($path, '.') !== false) {
            $params['_format'] = pathinfo($path, PATHINFO_EXTENSION);
            $path = substr($path, 0, - strlen($params['_format']) - 1);
        }

        $parts = $this->parsePath($path);

        // Split out namespace
        if (count($parts) > 1 && in_array($parts[0], $this->namespaces)) {
            $rootCtrl .= array_shift($parts) . '/';
        }

        // Split out scope
        if (count($parts) > 1 && in_array($parts[0], $this->scopes)) {
            $rootCtrl .= array_shift($parts) . '/';
        }

        $baseCtrl = $rootCtrl;

        // The first parameter must be controller name,
        // the second parameter may be action name or id, eg posts/show, posts/1
        // the last parameter may be controller name or action name or null, eg posts/1/comments, posts/1/edit
        $lastParts = array_pad(array_splice($parts, count($parts) % 2 == 0 ? -2 : -3), 3, null);
        list($ctrl, $actOrId, $ctrlOrAct) = $lastParts;

        // Generate part of controller name and query parameters
        $count = count($parts);
        for ($i = 0; $i < $count; $i += 2) {
            $baseCtrl .= $parts[$i] . '/';
            $params[$this->camelize($this->singularize($parts[$i])) . 'Id'] = $parts[$i + 1];
        }

        if (is_null($actOrId)) {
            // GET|POST|... /, GET|POST|... posts
            $routes[] = array(
                'controller' => $baseCtrl . ($ctrl ?: $this->defaultController),
                'action' => $this->methodToAction($method, true),
            );
        } elseif (is_null($ctrlOrAct)) {
            // GET posts/show
            if ($this->isAction($actOrId)) {
                $routes[] = array(
                    'controller' => $baseCtrl . $ctrl,
                    'action' => $actOrId,
                );
            }

            // GET|PUT|... posts/1
            $routes[] = array(
                'controller' => $baseCtrl . $ctrl,
                'action' => $this->methodToAction($method),
                'id' => $actOrId
            );

            // GET posts/1/comment/new => comment::new postId=1
            if ($count >= 2 && $this->isAction($actOrId)) {
                $routes[] = array(
                    'controller' => $rootCtrl . $ctrl,
                    'action' => $actOrId,
                );
            }
        } else {
            // GET posts/1/edit
            $routes[] = array(
                'controller' => $baseCtrl . $ctrl,
                'action' => $ctrlOrAct,
                'id' => $actOrId
            );

            // GET|PUT|... posts/1/comments
            $routes[] = array(
                'controller' => $baseCtrl . $ctrl . '/' . $ctrlOrAct,
                'action' => $this->methodToAction($method, true),
                $this->camelize($this->singularize($ctrl)) . 'Id' => $actOrId,
            );

            // GET|PUT|... posts/1/comments, use the last parameter as main controller name
            $routes[] = array('controller' => $rootCtrl . $ctrlOrAct) + $routes[1];
        }

        foreach ($routes as &$route) {
            $route['controller'] = $this->camelize($route['controller']);
            $route['action'] = $this->camelize($route['action']);
            $route += $params;
        }
        return $routes;
    }
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);
    }
254210
public function getMethodPrefix($method)
    {
        $method = strtolower($method);

        return isset($this->methodPrefix[$method]) ? $this->methodPrefix[$method] : null;
    }
1177136
protected function getCallParams($controller, $method, $params)
		{
			// variables
			$values     = is_array($params) ? $params : explode('/', $params);
			$ref        = new ReflectionMethod($controller, $method);
			$params     = $ref->getParameters();
			$args       = [];
	
			// map route segments to the method's parameters
			foreach ($params as /** @var \ReflectionParameter */ $param)
			{
				// parse signature [match, optional, type, name, default]
				preg_match('/<(required|optional)> (?:([\\\\a-z\d_]+) )?(?:\\$(\w+))(?: = (\S+))?/i', (string)$param, $matches);
	
				// assign untyped segments
				if ($matches[2] == null)
				{
					$args[$matches[3]] = array_shift($values);
				}
			}
	
			// append any remaining values
			return array_merge($args, $values);
		}
120694
public function route($method, $path, $callback)
    {
        Argument::i()
            //argument 1 should be a string
            ->test(1, 'string')
            //argument 2 should be a string
            ->test(2, 'string')
            //argument 3 should be callable
            ->test(3, 'callable');
        
        $method = strtoupper($method);
        
        if ($method === 'ALL') {
            return $this
                ->route('get', $path, $callback)
                ->route('post', $path, $callback)
                ->route('put', $path, $callback)
                ->route('delete', $path, $callback);
        }
        
        $this->routeMiddleware[$method][] = array($path, $callback);
        
        return $this;
    }
667968
protected function pathinfoInternal(?string $scheme, string $path, int $options = null)
    {
        $info = $options ? \pathinfo($path, $options) : \pathinfo($path);

        if (null !== $scheme) {
            $info['scheme'] = $scheme;
            $dirname = isset($info['dirname']) && $info['dirname'] !== '.' ? $info['dirname'] : null;

            if (null !== $dirname) {
                $info['dirname'] = $scheme . '://' . $dirname;
            } else {
                $info = ['dirname' => $scheme . '://'] + $info;
            }
        }

        return $info;
    }
1078460
public function request($method, $path = null, $parameters = array())
    {
        if (null === $path) {
            $url = '/messages';
        } else {
            $url  = '/messages/'.$path;
        }

        return json_decode($this->requestRaw($method, $url, $parameters), true);
    }