@param string $routesFolder
@param string $commandName

@return array

@throws ReflectionException

@SuppressWarnings(PHPMD.ExcessiveMethodLength)
320651
private function readExtraContainerConfiguratorsAndMiddleware(string $routesFolder, string $commandName): array
    {
        $routesFilter = new class ($commandName) implements RoutesInterface
        {
            use CheckCallableTrait;

            /** @var array */
            private $middleware = [];

            /** @var array */
            private $configurators = [];

            /** @var string */
            private $commandName;

            /**
             * @param string $commandName
             */
            public function __construct(string $commandName)
            {
                $this->commandName = $commandName;
            }

            /**
             * @inheritdoc
             */
            public function addGlobalMiddleware(array $middleware): RoutesInterface
            {
                assert($this->checkMiddlewareCallables($middleware) === true);

                $this->middleware = array_merge($this->middleware, $middleware);

                return $this;
            }

            /**
             * @inheritdoc
             */
            public function addGlobalContainerConfigurators(array $configurators): RoutesInterface
            {
                assert($this->checkConfiguratorCallables($configurators) === true);

                $this->configurators = array_merge($this->configurators, $configurators);

                return $this;
            }

            /**
             * @inheritdoc
             */
            public function addCommandMiddleware(string $name, array $middleware): RoutesInterface
            {
                assert($this->checkMiddlewareCallables($middleware) === true);

                if ($this->commandName === $name) {
                    $this->middleware = array_merge($this->middleware, $middleware);
                }

                return $this;
            }

            /**
             * @inheritdoc
             */
            public function addCommandContainerConfigurators(string $name, array $configurators): RoutesInterface
            {
                assert($this->checkConfiguratorCallables($configurators) === true);

                if ($this->commandName === $name) {
                    $this->configurators = array_merge($this->configurators, $configurators);
                }

                return $this;
            }

            /**
             * @return array
             */
            public function getMiddleware(): array
            {
                return $this->middleware;
            }

            /**
             * @return array
             */
            public function getConfigurators(): array
            {
                return $this->configurators;
            }

            /**
             * @param array $mightBeConfigurators
             *
             * @return bool
             */
            private function checkConfiguratorCallables(array $mightBeConfigurators): bool
            {
                $result = true;

                foreach ($mightBeConfigurators as $mightBeCallable) {
                    $result = $result === true &&
                        $this->checkPublicStaticCallable(
                            $mightBeCallable,
                            [LimoncelloContainerInterface::class],
                            'void'
                        );
                }

                return $result;
            }

            /**
             * @param array $mightBeMiddleware
             *
             * @return bool
             */
            private function checkMiddlewareCallables(array $mightBeMiddleware): bool
            {
                $result = true;

                foreach ($mightBeMiddleware as $mightBeCallable) {
                    $result = $result === true && $this->checkPublicStaticCallable(
                        $mightBeCallable,
                        [IoInterface::class, Closure::class, PsrContainerInterface::class],
                        'void'
                    );
                }

                return $result;
            }
        };

        foreach (static::selectClasses($routesFolder, RoutesConfiguratorInterface::class) as $class) {
            /** @var RoutesConfiguratorInterface $class */
            $class::configureRoutes($routesFilter);
        }

        return [$routesFilter->getConfigurators(), $routesFilter->getMiddleware()];
    }
689748
public function generate($routeName, array $parameters = [])
    {
        $route = $this->router->getRoute($routeName);

        $required = $route->getParameterPatterns();
        $missing  = array_diff_key($required, $parameters);

        if (!empty($missing)) {
            $parameters = $this->insertDefaultParameterValues($route, $missing, $parameters);
        }

        return $this->buildPath($route->getPath(), $parameters, array_keys($required));
    }
115859
public function actionGetAllRouteRules(string $format = 'Craft', $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getAllRouteRules($format, $siteId));
    }
710957
protected function collectionRouteList($routeName, Collection $collection, $key = 'id')
    {
        $keys = $collection->pluck($key);

        return array_map(function ($key) use ($routeName) {
            return route($routeName, $key);
        }, $keys->all());
    }
540857
final public function urlFor($routeName, array $params = array())
    {
        if (null === $this->router) {
            return '';
        }

        return $this->router->urlFor($routeName, $params);
    }
425109
public function listCommand()
    {
        $this->outputLine('Currently registered routes:');
        /** @var Route $route */
        foreach ($this->router->getRoutes() as $index => $route) {
            $uriPattern = $route->getUriPattern();
            $this->outputLine(str_pad(($index + 1) . '. ' . $uriPattern, 80) . $route->getName());
        }
    }
701520
protected function createRouteFor($routeKey, $slug, $intentedActions = null)
    {
        $controller = $this->getController();
        $action = $this->getAction($controller, $intentedActions);

        return array(
            '*',
            '/' . $this->defaultSlug ."/[$slug:rewrite]/?",
            $controller->getShortName() . "#" . $action
        );
    }
626454
public function compileRoute($prefixName, \ReflectionClass $class, \ReflectionMethod $method, Route $route = null)
    {
        $collection = new RouteCollection();

        $routeAnnotations = array();
        $methodAnnotaion = null;

        /*
         * Parse method annotation
         */
        $methodAnnotaions = $this->extractorFactory->extract($method, Extractor::METHOD_ANNOTATAION);
        foreach ($methodAnnotaions as $key => $annoation) {
            if ($annoation instanceof Route) {
                $routeAnnotations[] = $annoation;
            }
            if ($annoation instanceof Method) {
                $methodAnnotaion = $annoation;
            }
        }

        $name = $route->getName() ?: strtolower($prefixName.'_'.$method->getName());
        if (empty($routeAnnotations)) {
            $this->addRoute($class, $method, $collection, $name, $route, null, null);
        } else {
            foreach ($routeAnnotations as $routeAnnotation) {
                /* @var Route $routeAnnotation */
                $this->addRoute($class, $method, $collection, $name, $route, $routeAnnotation, $methodAnnotaion);
            }
        }

        return $collection;
    }
1352815
public function amOnRoute($routeName, array $params = [])
    {
        $router = $this->bootstrap->getBootstrap()->getResource('frontcontroller')->getRouter();
        $url = $router->assemble($params, $routeName);
        $this->amOnPage($url);
    }
1272141
public function getCommand($commandAlias)
    {
        if (!array_key_exists($commandAlias, $this->commands)) {
            throw new CommandException(sprintf('The command "%s" is not registered', $commandAlias));
        }

        return $this->commands[$commandAlias];
    }
48602
public function map($methods, $pattern, $callable)
	{
		$methods = (array) $methods;
		if (!is_string($pattern)) {
			throw new InvalidArgumentException('Route pattern must be a string');
		}
		
		// Prepend parent group pattern(s)
		if ($this->routeGroups) {
			$pattern = $this->processGroups() . $pattern;
		}
		
		// According to RFC methods are defined in uppercase (See RFC 7231)
		$methods = array_map("strtoupper", $methods);
		
		// Add route
		$route = $this->createRoute($methods, $pattern, $callable);
		$this->routes[$route->getIdentifier()] = $route;
		$this->routeCounter++;
		
		return $route;
	}
882814
public static function find($commandName, CommandCollection $commands)
    {
        $threshold = 1e3;
        $distancesByName = array();

        // Include aliases in the search
        $actualNames = $commands->getNames(true);

        foreach ($actualNames as $actualName) {
            // Get Levenshtein distance between the input and each command name
            $distance = levenshtein($commandName, $actualName);

            $isSimilar = $distance <= (strlen($commandName) / 3);
            $isSubString = false !== strpos($actualName, $commandName);

            if ($isSimilar || $isSubString) {
                $distancesByName[$actualName] = $distance;
            }
        }

        // Only keep results with a distance below the threshold
        $distancesByName = array_filter($distancesByName, function ($distance) use ($threshold) {
            return $distance < 2 * $threshold;
        });

        // Display results with shortest distance first
        asort($distancesByName);

        $suggestedNames = array_keys($distancesByName);

        return self::filterDuplicates($suggestedNames, $commands);
    }
867274
protected function _getCommands($controllerName)
    {
        $commands = [];

        foreach (get_class_methods($controllerName) as $method) {
            if (preg_match('#^(.*)Command$#', $method, $match) === 1 && $match[1] !== 'help') {
                $commands[] = $match[1];
            }
        }

        return $commands;
    }
1225703
public function get($command = null)
    {
        if (isset($command)) {
            $routes = $this->getList();
            return isset($routes[$command]) ? $routes[$command] : array();
        }

        return $this->route;
    }
614454
public function redirectToRoute($routeName, array $parameters = [])
    {
        $url = $this->router->getRouteUrlByName($routeName, $parameters);
        if (!$url) {
            throw new \Parable\Framework\Exception("Can't redirect to route, '{$routeName}' does not exist.");
        }
        $this->response->redirect($this->url->getUrl($url));
    }
124614
private function getUrlPattern(Router $router, $routeNameFromMappingFile, $baseUrl)
    {
        if (!empty($routeNameFromMappingFile)) {
            try {
                $route = $router->getRouteCollection()->get($routeNameFromMappingFile);
                if (empty($route)) {
                    throw new Exception();
                }
            } catch (Exception $e) {
                throw new RuntimeException(
                   \sprintf('Route \'%s\' has not been defined as a Symfony route.', $routeNameFromMappingFile)
               );
            }

            \preg_match_all('/{(.*?)}/', $route->getPath(), $matches);

            $pattern = [];
            if (!empty($matches)) {
                $pattern = \array_combine($matches[1], $matches[0]);
            }

            return $baseUrl.\urldecode($router->generate($routeNameFromMappingFile, $pattern, true));
        }

        return (string) $routeNameFromMappingFile;
    }
251047
public static function generate(
        $compiledRouterPath,
        callable $routeDefinitionsCallback,
        callable $routeCollectionFactory = null,
        callable $routerCompilerFactory = null,
        $forceCompile = false
    ) {
        if (!$forceCompile) {
            $compiledRouter = @include $compiledRouterPath;

            if ($compiledRouter) {
                return $compiledRouter;
            }
        }

        /** @var RouteCollection $routes */
        $routes = $routeCollectionFactory ? $routeCollectionFactory() : new RouteCollection(new RouteParser());

        /** @var RouterCompiler $routeParser */
        $routerCompiler = $routerCompilerFactory ? $routerCompilerFactory() : new TreeBasedRouterCompiler();

        $routeDefinitionsCallback($routes);

        file_put_contents($compiledRouterPath, $routerCompiler->compileRouter($routes));

        return require $compiledRouterPath;
    }