Método que extrae de la url los parámetros REST

@param string $route

@param string $pattern

@return array
18871
public static function extractComponents($route, $pattern)
    {
        Logger::log('Extracting parts for the request to execute');
        $url = parse_url(preg_replace("/\/\//", '/', $route));
        $partialRoute = explode('/', $url['path']);
        $partialPattern = explode('/', $pattern);
        $get = [];
        if (!empty($partialPattern)) {
            foreach ($partialPattern as $index => $component) {
                $query = [];
                preg_match_all('/^\{(.*)\}$/', $component, $query);
                if (!empty($query[1]) && isset($partialRoute[$index])) {
                    $get[array_pop($query[1])] = $partialRoute[$index];
                }
            }
        }

        return $get;
    }
726347
private function patternToPath($pattern, $params)
    {
        // Inspired by https://github.com/nikic/FastRoute/issues/66
        // but uses named params, don't care param order and size
        $routeParser = new RouteParserStd;
        $routes = $routeParser->parse($pattern);

        // check from the longest route to the shortest route
        // first (longest) full match is the route we need
        for ($i = count($routes) - 1; $i >= 0; $i--) {
            $url = '';
            foreach ($routes[$i] as $part) {
                // replace placeholder to actual value
                if (is_array($part)) {
                    $part = @$params[$part[0]];
                }

                // if route contains part not defined in $params, abandan this route
                if (null === $part) {
                    continue 2;
                }
                $url .= $part;
            }

            // first full match, this is our hero url
            return $url;
        }

        // no full match, throw Exception
        throw new \Exception(sprintf("Can't make path for '%s' with param: %s.", $pattern, json_encode($params)));
    }
226424
private function checkForMetaRoute($route)
    {
        $this->baseRoute = $route;
        $this->metaRoute = null;

        // If route exits in index, use it
        if ($this->mapRoute2IndexKey($route)) {
            return $route;
        }

        // Check for pagination
        $pagination = $this->config["pagination"];
        $matches = [];
        $pattern = "/(.*?)\/($pagination)\/(\d+)$/";
        if (preg_match($pattern, $route, $matches)) {
            $this->baseRoute = $matches[1];
            $this->metaRoute = $route;
            $this->currentPage = $matches[3];
        }

        return $this->baseRoute;
    }
620025
public static function matchRoutePattern($routePattern, $path)
    {
        $expr = preg_replace('/\{([^}]+)\}/', '###', $routePattern);
        $expr = preg_quote($expr, '/');
        $expr = str_replace('###', '(.*)', $expr);
        $expr2 = preg_replace('/\(\.\*\)$/', '', $expr);
        $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path);
        return $matched;
    }
869907
public static function compile(Route $route)
    {
        $staticPrefix = false;
        $variables = [];
        $pos = 0;
        $extractedRegexes = [];
        $defaults = [];

        // set correct static prefix
        $prefix = $route->getHost() == '' ? '' : $route->getHost() . '/';

        // route regex
        $routePatternObject = self::str($route->getPath())->trimLeft('/');

        // if path is empty
        // e.g. the path is empty if you are matching a start page
        if($routePatternObject->val()==''){
            return new CompiledRoute(false, false, [], [], false);
        }

        $routePattern = $prefix . $routePatternObject->val() . '$';

        // we append the regex to match the string from beginning only if the path starts with http or '/'
        if($routePatternObject->startsWith('http')) {
            $routePattern = '^' . $routePattern;
        }else if(self::str($route->getRealPath())->startsWith('/') && self::str($route->getRealPath())->length()>1){
            $routePattern = '^/' . $routePattern;
        }
        // set regex delimiters
        $routePattern = '#' . $routePattern . '#';

        // extract all variables
        preg_match_all('#\{\w+\}#', $route->getPath(), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
        foreach ($matches as $m) {
            $var = substr($m[0][0], 1, -1);

            // get all the text before the variable
            if(!$staticPrefix) {
                $prefix = substr($route->getPath(), $pos, ($m[0][1] - $pos));
                $pos = $m[0][1] + strlen($m[0][0]);
                $precedingChar = strlen($prefix) > 0 ? substr($prefix, -1) : '';
                if(strlen($precedingChar) === 1 && strpos(self::SEPARATORS, $precedingChar) !== false) {
                    $staticPrefix .= substr($prefix, 0, -1);
                } else {
                    $staticPrefix .= $prefix;
                }
            }

            $regex = '[\w-]+';
            $default = false;
            if($route->hasOption($var)) {
                // pattern
                if($route->getOptions()[$var]->hasAttribute('Pattern')) {
                    $regex = $route->getOptions()[$var]->getAttribute('Pattern');
                }

                // default
                if($route->getOptions()[$var]->hasAttribute('Default')) {
                    $default = $route->getOptions()[$var]->getAttribute('Default');
                }
            }
            $extractedRegexes[$var] = $regex;
            $defaults['{' . $var . '}'] = $default;

            $variables[] = ['name' => $var];
            $routePattern = str_replace($m[0][0], '(' . $regex . ')', $routePattern);
        }

        // build the default route
        $defaultRoute = false;
        if(count($defaults) > 0) {
            $defaultRoute = str_replace(array_keys($defaults), array_values($defaults), $route->getPath());
        }

        return new CompiledRoute($staticPrefix, $routePattern, $variables, $extractedRegexes, $defaultRoute);
    }
901083
public function isPatternMatches($pattern, $routePattern = false)
    {
        $uri = $this->removeIndexDotPhpAndTrillingSlash($this->getCurrentUri());
        $hasPattern = $this->hasNamedPattern($pattern);
        $pattern = ($hasPattern == false) ? $pattern : $hasPattern;
        if (preg_match_all(
            '#^' . $pattern . '$#',
            $uri,
            $matches,
            PREG_SET_ORDER
        )) {
            return $matches;
        }
    }
1222050
protected function getRouteInformation($route)
    {
        if (!is_a($route, 'Illuminate\Routing\Route')) {
            return [];
        }
        $uri = head($route->methods()) . ' ' . $route->uri();
        $action = $route->getAction();

        $result = [
           'uri' => $uri ?: '-',
        ];

        $result = array_merge($result, $action);


        if (isset($action['controller']) && strpos($action['controller'], '@') !== false) {
            list($controller, $method) = explode('@', $action['controller']);
            if(class_exists($controller) && method_exists($controller, $method)) {
                $reflector = new \ReflectionMethod($controller, $method);
            }
            unset($result['uses']);
        } elseif (isset($action['uses']) && $action['uses'] instanceof \Closure) {
            $reflector = new \ReflectionFunction($action['uses']);
            $result['uses'] = $result['uses'];
        }

        if (isset($reflector)) {
            $filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
            $result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine();
        }

        return $result;
    }
970717
protected static function dynamic($route)
    {
        $parms = [];
        $param = '';
        $open = false;
        //
        for ($i = 0; $i < Strings::length($route); $i++) {
            if ($open && $route[$i] != '}') {
                $param .= $route[$i];
            }
            //
            if ($route[$i] == '{' && !$open) {
                $open = true;
            } //
            elseif ($route[$i] == '}' && $open) {
                $open = !true;
                $parms[] = $param;
                $param = '';
            }
        }
        //
        return $parms;
    }
447558
public function put($rule, $route = '', array $option = [], array $pattern = [])
    {
        return $this->rule($rule, $route, 'PUT', $option, $pattern);
    }
712107
private function routeMatch(string $routeRegex, string $route)
    {
        $matches = [];
        if (preg_match($routeRegex, $route, $matches)) {
            unset($matches[0]);

            return array_values($matches);
        }

        return false;
    }
1172226
public function findStaticRoute($method, $pattern)
    {
        $method = strtolower($method);
        if (isset($this->statics[$method]) && isset($this->statics[$method][$pattern]))
            return $this->statics[$method][$pattern];
        return false;
    }
1290267
protected function getRoutePathParameters($route)
	{
		$parameters = [];

		$routeAction = $route->getAction();
		list($class, $method) = explode('@', $routeAction['uses']);

		$reflection = new ReflectionClass($class);
		$reflectionMethod = $reflection->getMethod($method);

		foreach ($reflectionMethod->getParameters() as $parameter) {
			$reflectionType = $parameter->getType();
			// Only scalar types or undefined types
			if (is_null($reflectionType) || $reflectionType->isBuiltin()) {
				$parameters[$parameter->getName()] = [
					'name' => $parameter->getName(),
				];
				if (!is_null($reflectionType) && $reflectionType->isBuiltin()) {
					$parameters[$parameter->getName()]['type'] = (string)$parameter->getType();
				}
			}
		}

		if (count($parameters) > 0) {
			// Inject the related phpdoc if exists.
			$comment = $reflectionMethod->getDocComment();
			if ($comment) {
				$docBlock = $this->docBlockFactory->create($comment);
				foreach ($docBlock->getTagsByName('param') as $tag) {
					foreach ($parameters as $parameterName => $parameter) {
						if ($tag->getVariableName() == $parameterName) {
							$docDescription = $tag->getDescription()->render();
							/** @var \ReflectionType $reflectionType */
							$reflectionType = $tag->getType();
							$parameters[$parameterName]['docType'] = (string)$reflectionType;
							$parameters[$parameterName]['docDescription'] = $docDescription;
						}
					}
				}
			}
		}

		return $parameters;
	}
55322
public function delete($rule, $route = '', array $option = [], array $pattern = [])
    {
        return $this->rule($rule, $route, 'DELETE', $option, $pattern);
    }
75177
private function buildParam(Route $route): array
    {
        $param = [];

        $url = \explode('/', $route->url);
        $matches = \explode('/', $this->routeMatches[0]);

        $rawParam = \array_diff($matches, $url);

        foreach ($rawParam as $key => $value) {
            $paramName = \strtr($url[$key], ['[' => '', ']' => '']);
            $param[$paramName] = $value;
        }

        return $param;
    }
817239
protected static function funcGet($route)
    {
        $params = self::dynamic($route);
        //
        if (count($params) > 0) {
            return 'get(\''.$route.'\',function('.self::formatParams($params).')';
        } else {
            return 'get(\''.$route.'\',function()';
        }
    }
1256773
public function extractRoutePath(string $route)
    {
        $url = (strpos($route, '/') === false) ? url($route) : $route;
        $this->router->handle($url);

        return $this->router->getMatchedRoute()->getPaths();
    }
285416
protected function getUrl($route, $params = array())
    {
        $urlHelper = $this->getView()->plugin('url');

        if ('#' === $route[0]) {
            return $route;
        }

        return $urlHelper($route, $params, $this->getRouteOptions());
    }