buildRouter
Build the router for matching requests to controllers,
extended by children kernels.

@return Symfony\Component\Router\Matcher\RequestMatcherInterface $router
169069
protected function buildRouter()
    {
        $routes = new RouteCollection();
        $context = new RequestContext();
        $router = new UrlMatcher($routes, $context);

        return($router);
    }
575985
public function getRouter()
    {
        if (!isset($this->router)) {
            $container = clone $this->getContainer();
            $container->delegate(new ReflectionContainer);
            $this->router = (new RouteCollection($container));
        }

        /** @var RouteCollection $router */
        $router = $this->validateContract($this->router, RouteCollection::class);
        return $router;
    }
813394
function build(iRouterStack $router)
    {
        foreach($this->routes as $routeName => $routeValuable)
        {
            $route = $routeValuable;

            if ( is_string($routeName) && is_array($routeValuable) ) {
                // when route provided as array options
                $route = $this->_attainRouteFromArray($routeName, $routeValuable);
                $override = (isset($routeValuable['override']))  ? $routeValuable['override'] : true;
                $priority = (isset($routeValuable['priority']))  ? $routeValuable['priority'] : null;
            }

            if (! $route instanceof  iRoute )
                throw new \InvalidArgumentException(sprintf(
                    'Invalid argument provided. ("%s")'
                    , \Poirot\Std\flatten($routeValuable)
                ));



            # add router
            if ( isset($override) && isset($priority) )
                ## just if override option provided
                $router->add($route, $override, $priority);
            else
                ## using default value
                $router->add($route);
        }
    }
675762
public function getRouter()
    {
        if (is_null($this->_router)) {
            $this->_router = new Router($this);
        }
        return $this->_router;
    }
479144
public function compile()
    {
        $optionals = $this->getOptionalParameters();

        $uri = preg_replace('/\{(\w+?)\?\}/', '{$1}', $this->route->uri());

        return (
            new SymfonyRoute($uri, $optionals, $this->route->wheres, ['utf8' => true], $this->route->getDomain() ?: '')
        )->compile();
    }
604144
public function build(&$url = '', $fqr = true)
    {
        if (is_array($url)) {
            $url = '?'.http_build_query($url, '', '&');
        }

        $url = (string) $url;

        //remove the index.php for urls that starts with index.php?
        if (strpos($url, 'index.php?') === 0) {
            $url = substr($url, 9);
        }
        //add ? to the urls that starts with a query key=
        //elseif ( preg_match('/^\w+=/', $url) ) {
        elseif (preg_match('%^[^?/]+=%', $url)) {
            $url = '?'.$url;
        }

        $uri = clone $this->_clonable_url;

        $uri->setUrl($url);

        if ($uri->scheme || $uri->path) {
            return $uri;
        }

        $query = $uri->query;

        if (isset($query['format'])) {
            $uri->format = $query['format'];
            unset($query['format']);
        }

        if ($uri->format == 'html') {
            $uri->format = null;
        }

        $parts = array();

        if (isset($query['option'])) {
            $router = $this->getComponentRouter(str_replace('com_', '', $query['option']));
            $parts = pick($router->build($query), array());
        }

        if (isset($query['option'])) {
            array_unshift($parts, str_replace('com_', '', $query['option']));
            unset($query['option']);
        }

        $uri->query = $query;

        if (!$this->_enable_rewrite) {
            array_unshift($parts, 'index.php');
        } elseif (empty($parts)) {
            array_unshift($parts, '');
        }

        array_unshift($parts, $this->_base_url->path);

        $path = implode('/', $parts);

        $uri->path = $path;

        if ($fqr) {
            foreach (array('host', 'scheme', 'port', 'user', 'pass') as $part) {
                $uri->$part = $this->_base_url->$part;
            }
        }

        return $uri;
    }
723303
public function getRouter() {
        $routesIni = $this->_getRoutesConfig();
        $this->setOptions($routesIni->toArray());
        $options = $this->getOptions();

        if ($this->_localeIsEnabled()) {
            $bootstrap = $this->getBootstrap();

            if (!$this->_locale) {
                $bootstrap->bootstrap('Locale');
                $this->_locale = $bootstrap->getContainer()->locale;
            }

            $defaultLocale = array_keys($this->_locale->getDefault());
            $defaultLocale = $defaultLocale[0];

            $locales = $this->_getPossibleLocales();
            $routes = $options['routes'];
            $localizedRoutes = Garp_I18n::getLocalizedRoutes($routes, $locales);
            $options['routes'] = array_merge($routes, $localizedRoutes);
            $this->setOptions($options);
        }

        $router = parent::getRouter();
        $router->addDefaultRoutes();
        return $router;
    }
231474
public function build(): SetBypassServiceWorkerRequest
	{
		$instance = new SetBypassServiceWorkerRequest();
		if ($this->bypass === null) {
			throw new BuilderException('Property [bypass] is required.');
		}
		$instance->bypass = $this->bypass;
		return $instance;
	}
827237
public RouterConfiguration build() {
        return new RouterConfiguration(routingBuilder.build(), hotRodRouterBuilder.build(), restRouterBuilder.build(), singlePortRouterBuilder.build());
    }
762616
public function dispatch($router)
    {
        $context = $this->_context;

        if ($router instanceof RouterContext) {
            $area = $router->area;
            $controller = $router->controller;
            $action = $router->action;
            $params = $router->params;
        } else {
            $area = $router->getArea();
            $controller = $router->getController();
            $action = $router->getAction();
            $params = $router->getParams();
        }

        if ($area) {
            $area = strpos($area, '_') === false ? ucfirst($area) : Text::camelize($area);
            $context->area = $area;
        }

        $controller = strpos($controller, '_') === false ? ucfirst($controller) : Text::camelize($controller);
        $context->controller = $controller;

        $action = strpos($action, '_') === false ? $action : lcfirst(Text::camelize($action));
        $context->action = $action;

        $context->params = $params;

        if ($area) {
            if ($action === 'index') {
                if ($controller === 'Index') {
                    $context->path = $area === 'Index' ? '/' : '/' . Text::underscore($area);
                } else {
                    $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller);
                }
            } else {
                $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        } else {
            if ($action === 'index') {
                $context->path = $controller === 'Index' ? '/' : '/' . Text::underscore($controller);
            } else {
                $context->path = '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        }

        $controllerClassName = $this->_getControllerClassName();

        /**
         * @var \ManaPHP\Rest\Controller $controllerInstance
         */
        $controllerInstance = $this->_di->getShared($controllerClassName);
        $context->controllerInstance = $controllerInstance;

        return $this->invokeAction($controllerInstance, $action, $params);
    }
767646
public function setRouter(Symfony\Component\Routing\Router $router)
    {
        $this->router = $router;

        return $this;
    }
141554
public function & GetRouter () {
		if ($this->router === NULL) {
			$routerClass = $this->routerClass;
			$this->router = & $routerClass::GetInstance();
		}
		return $this->router;
	}
876983
public function getController() {
        $router = new Router($this);
        $router->setCurrentRoute();
        $controllerObject = $this->GetControllerObject($router);
        $this->controller = $controllerObject;
        return $controllerObject;
    }
432117
public function getMatcher()
    {
        if (null !== $this->matcher) {
            return $this->matcher;
        }

        $compiled = is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true) && (UrlMatcher::class === $this->options['matcher_base_class'] || RedirectableUrlMatcher::class === $this->options['matcher_base_class']);

        if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
            $routes = $this->getRouteCollection();
            if ($compiled) {
                $routes = (new CompiledUrlMatcherDumper($routes))->getCompiledRoutes();
            }
            $this->matcher = new $this->options['matcher_class']($routes, $this->context);
            if (method_exists($this->matcher, 'addExpressionLanguageProvider')) {
                foreach ($this->expressionLanguageProviders as $provider) {
                    $this->matcher->addExpressionLanguageProvider($provider);
                }
            }

            return $this->matcher;
        }

        $cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['matcher_cache_class'].'.php',
            function (ConfigCacheInterface $cache) {
                $dumper = $this->getMatcherDumperInstance();
                if (method_exists($dumper, 'addExpressionLanguageProvider')) {
                    foreach ($this->expressionLanguageProviders as $provider) {
                        $dumper->addExpressionLanguageProvider($provider);
                    }
                }

                $options = [
                    'class' => $this->options['matcher_cache_class'],
                    'base_class' => $this->options['matcher_base_class'],
                ];

                $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
            }
        );

        if ($compiled) {
            return $this->matcher = new $this->options['matcher_class'](require $cache->getPath(), $this->context);
        }

        if (!class_exists($this->options['matcher_cache_class'], false)) {
            require_once $cache->getPath();
        }

        return $this->matcher = new $this->options['matcher_cache_class']($this->context);
    }
2921
public function build()
    {
        $routeCollection = new RouteCollection();

        foreach ($this->routes as $name => $route) {
            if ($route instanceof Route) {
                $route->setDefaults(array_merge($this->defaults, $route->getDefaults()));
                $route->setOptions(array_merge($this->options, $route->getOptions()));

                foreach ($this->requirements as $key => $val) {
                    if (!$route->hasRequirement($key)) {
                        $route->setRequirement($key, $val);
                    }
                }

                if (null !== $this->prefix) {
                    $route->setPath('/'.$this->prefix.$route->getPath());
                }

                if (!$route->getHost()) {
                    $route->setHost($this->host);
                }

                if (!$route->getCondition()) {
                    $route->setCondition($this->condition);
                }

                if (!$route->getSchemes()) {
                    $route->setSchemes($this->schemes);
                }

                if (!$route->getMethods()) {
                    $route->setMethods($this->methods);
                }

                // auto-generate the route name if it's been marked
                if ('_unnamed_route_' === substr($name, 0, 15)) {
                    $name = $this->generateRouteName($route);
                }

                $routeCollection->add($name, $route);
            } else {
                /* @var self $route */
                $subCollection = $route->build();
                $subCollection->addPrefix($this->prefix);

                $routeCollection->addCollection($subCollection);
            }
        }

        foreach ($this->resources as $resource) {
            $routeCollection->addResource($resource);
        }

        return $routeCollection;
    }
1262738
public function map(Router $router)
    {
        $config = $this->app['config']['optimus.components'];

        $middleware = $config['protection_middleware'];

        $highLevelParts = array_map(function ($namespace) {
            return glob(sprintf('%s%s*', $namespace, DIRECTORY_SEPARATOR), GLOB_ONLYDIR);
        }, $config['namespaces']);

        foreach ($highLevelParts as $part => $partComponents) {
            foreach ($partComponents as $componentRoot) {
                $component = substr($componentRoot, strrpos($componentRoot, DIRECTORY_SEPARATOR) + 1);

                $namespace = sprintf(
                    '%s\\%s\\Controllers',
                    $part,
                    $component
                );

                $fileNames = [
                    'routes' => true,
                    'routes_protected' => true,
                    'routes_public' => false,
                ];

                foreach ($fileNames as $fileName => $protected) {
                    $path = sprintf('%s/%s.php', $componentRoot, $fileName);

                    if (!file_exists($path)) {
                        continue;
                    }

                    $router->group([
                        'middleware' => $protected ? $middleware : [],
                        'namespace'  => $namespace,
                    ], function ($router) use ($path) {
                        require $path;
                    });
                }
            }
        }
    }
376466
public function getRouteBuilder()
    {
        if (null == $this->routeBuilder) {
            $this->setRouteBuilder(new RouteBuilder($this->getRouteFile()));
        }
        return $this->routeBuilder;
    }