Sort routes by their URI pattern.

@param Route[] $routes

@return Route[]
513525
private function sortPattern(array $routes)
    {
        uasort($routes, function (Route $a, Route $b) {
            if ($a->getPath() === $b->getPath()) {
                return 0;
            }
            $a = str_replace('{', '', str_replace('}', '', $a->getPath()));
            $b = str_replace('{', '', str_replace('}', '', $b->getPath()));

            return ($a < $b) ? -1 : 1;
        });

        return $routes;
    }
22588
public function group(array $routes)
    {
        $group = new Group;
        foreach ($routes as $route)
            $group->set($route);
        return $group;
    }
1297958
public function addRoutes(array $routes = [])
    {
        foreach($routes as $route)
        {
            if ($route instanceof RouteInterface) $this->routes[] = $route;
        }
    }
119188
private function _getRouteMatch($path,$routes)
	{
		foreach ($routes as $route)
		{
			if ($match = $route->getMatch($path, $this->metadata($route->getName())))
				return $match;
		}
		return false;
	}
293125
public function match(string $route): array
    {
        if (!isset($this->routes[$route])) {
            return [];
        }

        return $this->routes[$route];
    }
1188241
private function mapRoute2Content($route)
    {
        // Look it up in the index
        list($keyIndex, $content) = $this->mapRoute2Index($route);
        $filtered = $this->loadFileContentPhaseOne($keyIndex);

        return [$keyIndex, $content, $filtered];
    }
789252
public function gatherRouteMiddlewares(LaravelRoute $route)
    {
        $middlewares = [];

        foreach ($route->middleware() as $name) {
            $middlewares[] = $this->resolveMiddlewareClassName($name);
        }
        return Arr::flatten($middlewares);
    }
711774
public function getDefaults($route)
    {
        $route = $this->router->getRouteCollection()->get($route);
        if ($route) {
            $defaults = $route->getDefaults();

            return $defaults;
        }

        return array();
    }
630807
protected function getRoutes()
    {
        $routes = [];
        foreach ($this->routes as $collection) {
            foreach ($collection->getRoutes() as $route) {
                $uses = array_key_exists('uses', $route->getAction())
                    ? $route->getAction()['uses']
                    : $route->getActionName();

                $routes[] = $this->filterRoute([
                    'host' => $route->domain(),
                    'method' => implode('|', $route->methods()),
                    'uri' => $route->uri(),
                    'name' => $route->getName(),
                    'action' => $uses,
                    'middleware' => $route->getMiddleware() ? implode(", ", $route->getMiddleware()) : "No",
                    'protected' => $route->isProtected() ? 'Yes' : 'No',
                    'versions' => implode(', ', $route->versions()),
                    'scopes' => implode(', ', $route->scopes()),
                    'rate' => $this->routeRateLimit($route),
                ]);
            }
        }

        if ($sort = $this->option('sort')) {
            $routes = Arr::sort($routes, function ($value) use ($sort) {
                return $value[$sort];
            });
        }
        if ($this->option('short')) {
            $this->headers = ['Method', 'URI', 'Name', 'Version(s)'];
            $routes = array_map(function ($item) {
                return array_only($item, ['method', 'uri', 'name', 'versions']);
            }, $routes);
        }
        return array_filter(array_unique($routes, SORT_REGULAR));
    }
826980
private static function extractAttributesFromRoutes($url, $routes)
    {
        $attributes = [];

        foreach ($routes as $route) {
            /**
             * @var  \Illuminate\Routing\Route  $route
             * @var  \Illuminate\Http\Request   $request
             */
            $request = Request::create(implode('/', $url));

            if ( ! $route->matches($request))
                continue;

            $match = self::hasAttributesFromUriPath($url, $route->uri(), $attributes);

            if ($match)
                break;
        }

        return $attributes;
    }
1313475
private function getRoutesFromIndexActions (&$routes, array &$routeActions, &$requestMethod, array &$requestPathParts) {
        foreach ($routeActions as $routeData) {
            $routePath = $routeData[0];
            $routeAction = $routeData[1];
            $routeParameters = [];
            if (strpos($routePath, self::ROUTE_PARAMETER_PREFIX) !== false || strpos($routePath, self::ROUTE_GENERIC_PATH) !== false) {
                $routePathParts = explode(self::ROUTE_PATH_SEPARATOR, trim($routePath, self::ROUTE_PATH_SEPARATOR));;
                for ($i = 0; $i < sizeof($routePathParts); $i++) {
                    $routePathPart = $routePathParts[$i];
                    if ($routePathPart == self::ROUTE_GENERIC_PATH) {
                        $path = array_slice($requestPathParts, $i);
                        $routeParameters[self::ROUTE_PATH_PARAMETER_NAME] = $path;
                        break;
                    }
                    else if ($routePathPart[0] == self::ROUTE_PARAMETER_PREFIX) {
                        $parameterName = substr($routePathPart, 1);
                        $parameterValue = $requestPathParts[$i];
                        $routeParameters[$parameterName] = $parameterValue;
                    }
                }
            }
            if ($routeAction instanceof RouteGenerator) {
                $route = $routeAction->generateRoute($requestMethod, isset($path)?$path : $requestPathParts);
                if ($route) {
                    $routes[] = $route;
                }
            }
            else {
                $routes[] = new Route($routeAction, $routeParameters);
            }
        }
    }
1274262
protected function loadRoutes($routes)
    {
        if ($routes instanceof Closure) {
            $routes($this);
        } else {
            (new RouteFileRegistrar($this))->register($routes);
        }
    }
1049065
public function getRoutes() : array {
        $request = get_request();
        $requestMethod = $request->method();
        $requestPathParts = $request->pathParts();
        $routesIndex = $this->routesIndex;
        $routes = [];
        $this->getRoutesFromIndex($routes,$routesIndex, $requestMethod, $requestPathParts);
        return $routes;
    }
213544
protected function prepareListReportRoute(array &$routes)
    {
        $permissions = $this->getPermissionsReportRole();

        foreach ($routes as $pattern => &$route) {

            if (strpos($pattern, 'admin') === 0 && !isset($route['access'])) {
                $route['access'] = 'admin';
            }

            if (!isset($route['access'])) {
                $route['access'] = GC_PERM_PUBLIC;
            }

            $access_names = array();

            if (isset($permissions[$route['access']])) {
                $access_names[$route['access']] = $this->text($permissions[$route['access']]);
            } else {
                $access_names[''] = $this->text($permissions[GC_PERM_PUBLIC]);
            }

            if ($route['access'] === GC_PERM_SUPERADMIN) {
                $access_names = array(GC_PERM_SUPERADMIN => $this->text($permissions[GC_PERM_SUPERADMIN]));
            }

            $route['pattern'] = $pattern;
            $route['access_name'] = implode(' + ', $access_names);
            $route['access'] = implode('', array_keys($access_names));
            $route['status'] = !isset($route['status']) || !empty($route['status']);
        }
    }
324106
public function getAliases($route)
    {
        $aliases = [];

        if (is_array($this->routes[$route]) && array_key_exists('aliases', $this->routes[$route])) {
            $aliases = $this->routes[$route]['aliases'];
        }

        return $aliases;
    }
961014
protected static function prepare( $routes ) 
	{	
		// flatten if needed
		if ( ClanCats::$config->get( 'router.flatten_routes' ) ) 
		{
			$routes = static::flatten( $routes ); 
		}
		
		foreach( $routes as $uri => $route ) 
		{	
			// check for an alias to a private
			if ( is_string( $route ) ) 
			{
				if ( substr( $route, 0, 1 ) == '#' ) 
				{
					$route = static::$privates[$route];
				}
			}
			
			// does this uri contain an alias?
			if ( strpos( $uri, '@' ) !== false )
			{
				// is the entire route an alias
				if ( $uri[0] == '@' )
				{
					static::$aliases[substr( $uri, 1 )] = $route;
				}
				// does it just contain an alias
				else
				{
					list( $uri, $alias ) = explode( '@', $uri );
					static::$aliases[$alias] = $uri;
				}
			}
			
			// check for a private 
			if ( substr( $uri, 0, 1 ) == '#' ) 
			{
				static::$privates[$uri] = $route;
			}
			// just a normal one
			else 
			{
				static::$routes[$uri] = $route;
			}
		}
	}
689367
protected function headerLink(array $routes)
    {
        $links = [];
        foreach ($routes as $rel => $route) {
            $links[] = '<' . $this->url . $route . '>; rel="' . $rel . '"';
        }
        return implode(', ', $links);
    }