prepareRouter
Build the route matchers and router.

@return MicroCMS\Routing\Router $router
514606
public function prepareRouter()
    {
        $router = new Router();

        // Inject Logger if we have one
        if ($this->logger) {
            $router->setLogger($this->logger);
        }

        // Build the matcher stack
        $router->addMatcher($this->buildDefaultMatcher());

        if ($this->hasRoutingTemplates()) {
            $router->addMatcher($this->buildTemplateMatcher());
        }

        if ($this->hasRoutingConfig()) {
            $router->addMatcher($this->buildSymfonyMatcher());
        }

        return($router);
    }
1335213
protected function getRouter()
    {
        return isset($this->laravel->router) ? $this->laravel->router : $this->laravel;
    }
763470
protected function cloneLaravelRouter()
    {
        $router = clone $this->app['router'];
        $router->aliasMiddleware('api.auth', NodesHttpMiddlewareAuth::class);
        $router->aliasMiddleware('api.controllers', NodesHttpMiddlewarePrepareController::class);
        $router->aliasMiddleware('api.throttle', NodesHttpMiddlewareRateLimit::class);
        $router->aliasMiddleware('api.useragent', NodesHttpMiddlewareUserAgent::class);
        $router->aliasMiddleware('api.meta', NodesHttpMiddleware::class);

        return $router;
    }
154840
public function map()
    {
        Route::namespace($this->namespace)->group(function (Router $router) {

            /*
             * Front office routes
             */
            $router->middleware('web')->group(function (Router $router) {
                foreach (locales() as $lang) {
                    if (config('typicms.register')) {
                        // Registration
                        $router->get($lang.'/register', 'RegisterController@showRegistrationForm')->name($lang.'::register');
                        $router->post($lang.'/register', 'RegisterController@register');
                        // Verify
                        $router->get($lang.'/email/verify', 'VerificationController@show')->name($lang.'::verification.notice');
                        $router->get($lang.'/email/verify/{id}', 'VerificationController@verify')->name($lang.'::verification.verify');
                        $router->get($lang.'/email/resend', 'VerificationController@resend')->name($lang.'::verification.resend');
                    }
                    // Login
                    $router->get($lang.'/login', 'LoginController@showLoginForm')->name($lang.'::login');
                    $router->post($lang.'/login', 'LoginController@login');
                    // Request new password
                    $router->get($lang.'/password/reset', 'ForgotPasswordController@showLinkRequestForm')->name($lang.'::password.request');
                    $router->post($lang.'/password/email', 'ForgotPasswordController@sendResetLinkEmail')->name($lang.'::password.email');
                    // Set new password
                    $router->get($lang.'/password/reset/{token}', 'ResetPasswordController@showResetForm')->name($lang.'::password.reset');
                    $router->post($lang.'/password/reset', 'ResetPasswordController@reset');
                    // Logout
                    $router->post($lang.'/logout', 'LoginController@logout')->name($lang.'::logout');
                }
            });

            /*
             * Admin routes
             */
            $router->middleware('admin')->prefix('admin')->group(function (Router $router) {
                $router->get('users', 'AdminController@index')->name('admin::index-users')->middleware('can:see-all-users');
                $router->get('users/create', 'AdminController@create')->name('admin::create-user')->middleware('can:create-user');
                $router->get('users/{user}/edit', 'AdminController@edit')->name('admin::edit-user')->middleware('can:update-user');
                $router->post('users', 'AdminController@store')->name('admin::store-user')->middleware('can:create-user');
                $router->put('users/{user}', 'AdminController@update')->name('admin::update-user')->middleware('can:update-user');
            });

            /*
             * API routes
             */
            $router->middleware('api')->prefix('api')->group(function (Router $router) {
                $router->middleware('auth:api')->group(function (Router $router) {
                    $router->get('users', 'ApiController@index')->middleware('can:see-all-users');
                    $router->post('users/current/updatepreferences', 'ApiController@updatePreferences')->middleware('can:update-preferences');
                    $router->patch('users/{user}', 'ApiController@updatePartial')->middleware('can:update-user');
                    $router->delete('users/{user}', 'ApiController@destroy')->middleware('can:delete-user');
                });
            });
        });
    }
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;
    }
686047
public function prepareResponse()
    {
        try {
            $this->setBaseMiddlewares();
            $this->handleRequest($this->middlewares);
            $this->router->build();
            $this->handleRequest($this->routeMiddlewares);
            $this->response = $this->router->run();
        } catch (Exception $exception) {
            $response = $this->container->call([$this->getExceptionHandler(), 'render'], [$exception]);
            $this->response = $response ?: $this->response;
        }
    }
578134
private function router()
    {
        $routes = require $this->config['paths']['routes'];
        $request = \Zend\Diactoros\ServerRequestFactory::fromGlobals();

        $cacheFileName = 'routes.'.filemtime($this->config['paths']['routes']).'.cache';
        $cacheFile = $this->config['paths']['routesCache'].'/'.$cacheFileName;

        if (!file_exists($cacheFile)) {
            array_map('unlink', glob($this->config['paths']['routesCache'].'/*.cache'));
        }

        $dispatcher = \FastRoute\cachedDispatcher(
            function(\FastRoute\RouteCollector $r) use ($routes) {
                foreach ($routes as $route) {
                    $r->addRoute($route['methods'], $route['endpoint'], $route['call']);
                }
            },
            [
                'cacheFile' => $cacheFile,
            ]
        );

        $request = $request->withHeader('lang', $this->config['lang']);
        $request = $request->withHeader('config', json_encode($this->config));

        $routeInfo = $dispatcher->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        $response = new \Zend\Diactoros\Response();

        switch ($routeInfo[0]) {

            case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
                $response->getBody()->write('METHOD NOT ALLOWED');
                $response = $response->withStatus(405);
                $this->response = $response;
                break;

            case \FastRoute\Dispatcher::NOT_FOUND:
            case \FastRoute\Dispatcher::FOUND:

                $handler = isset($routeInfo[1]) ? $routeInfo[1] : $this->config['config']['not_found_controller'];
                $vars = isset($routeInfo[2]) ? $routeInfo[2] : [];
                $handler = explode('::', $handler);
                $class = $handler[0];
                $method = $handler[1];

                $response = (new \SideDevOrg\MiniPhpFw\Resolver())->dispatch(
                    $class,
                    $method,
                    $vars,
                    $request,
                    $response,
                    $middlewares = require $this->config['paths']['middlewares']
                );

                if (!isset($routeInfo[1])) {
                    $response = $response->withStatus(404);
                }
                $this->response = $response;
                break;
        }
    }
823978
protected function buildRoute(Route $route)
    {
        if ($route->getBlock()) {
            return $route;
        }

        list($pattern, $params) = $this->parsePlaceholders($route->getPattern());
        return $route->setPatternWithoutReset($pattern)->setParams($params)->setBlock(true);
    }
223592
public function build() : RouterInterface
    {
        $router = $this->router;
        try{
            foreach($this->modules as $module)
            {
                $module->install($router);
            }
        }
        catch(\Throwable $e)
        {
            throw new RouterBuildingException($e);
        }
        return $router;
    }
703792
public function instantiate()
    {
        $router = new Wildcard($this->entryPoint);
        $router->setLogger($this->app->getLogger());
        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);
        }
    }
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;
    }
83595
private function _route() {
        $this->profiler->addTime('route');

        $router = new Router($this);

        foreach ($this->config->config['route'] as $key => $value) {
            foreach ($value as $data) {
                $vars = explode(',', $data['vars']);
                $controller = explode('.', $data['action'])[0];
                $action = explode('.', $data['action'])[1];

                $router->addRoute(new Route($data['url'], $controller, $action, $data['name'], $data['cache'], $vars, $key, $data['logged'], $data['access'], $data['method']));
            }
        }

        $this->request->data->post = $_POST;
        $this->request->data->get = $_GET;
        $this->request->data->file = $_FILES;
        $this->request->data->method = strtolower($_SERVER['REQUEST_METHOD']);

        if (isset($_GET['request-get']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
            $this->request->data->form = true;
            $this->request->data->method = 'get';
        }
        else if (isset($_POST['request-post'])) {
            $this->request->data->form = true;
            $this->request->data->method = 'post';
        }
        else if (isset($_POST['request-put'])) {
            $this->request->data->form = true;
            $this->request->data->method = 'put';
            $this->request->data->put = $_POST;
        }
        else if (isset($_POST['request-patch'])) {
            $this->request->data->form = true;
            $this->request->data->method = 'patch';
            $this->request->data->patch = $_POST;
        }
        else if (isset($_POST['request-delete'])) {
            $this->request->data->form = true;
            $this->request->data->method = 'delete';
            $this->request->data->delete = $_POST;
        }

        if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
            parse_str(file_get_contents("php://input"), $put_vars);
            $this->request->data->put = $put_vars;
        }
        else if ($_SERVER['REQUEST_METHOD'] == 'PATCH') {
            parse_str(file_get_contents("php://input"), $patch_vars);
            $this->request->data->patch = $patch_vars;
        }
        else if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
            parse_str(file_get_contents("php://input"), $delete_vars);
            $this->request->data->delete = $delete_vars;
        }

        if ($matchedRoute = $router->getRoute(preg_replace('`\?' . preg_quote($_SERVER['QUERY_STRING']) . '`isU', '', $_SERVER['REQUEST_URI']), $this->config)) {
            $_GET = array_merge($_GET, $matchedRoute->vars());

            $this->request->name = $matchedRoute->name();
            $this->request->src = $matchedRoute->src();
            $this->request->controller = $matchedRoute->controller();
            $this->request->action = $matchedRoute->action();
            $this->request->logged = $matchedRoute->logged();
            $this->request->access = $matchedRoute->access();
            $this->request->method = $matchedRoute->method();
            $this->request->auth = new Auth($this->request->src);

            if ($this->config->config['user']['output']['cache']['enabled'] && $matchedRoute->cache() != '') {
                $this->request->cache = $matchedRoute->cache();
            }
            else {
                $this->request->cache = 0;
            }

            if ($this->request->action == '') {
                $this->request->action = 'default';
            }

            $this->_route = true;
        }

        $this->profiler->addTime('route', Profiler::USER_END);

        return $this;
    }
950744
protected function getRouter()
    {
        if (null === $this->router)
        {
            $this->router = $this->getContainer()->get('router');
        }

        return $this->router;
    }
1150322
public function initRouterDi()
    {
        $config = $this->getConfig();
        if (!isset($config['router'])) {
            throw new Exception\RuntimeException('Cannot init DI for router. Cannot find router configuration');
        }
        $config = $config['router']->toArray();
        $router = new Router($this->diFactory);
        foreach ($config as $name => $routeInfo) {
            $router->addRoute($name, $routeInfo);
        }

        $this->diFactory->set('router', $router, true);

        return $this;
    }
632094
public function buildRouter() : HTTPRouter
    {
        // create router dependencies and router instance
        $request = new HTTPInputRequestDefault();
        $response = new HTTPOutputResponseDefault($request);
        $errHandler = new HTTPErrorHandlerDefault();
        $router = new HTTPRouterDefault($request, $response, $errHandler);

        // prepare authorizations
        $authorizationDisabled = new AuthorizationDisabled();

        // add your routes here
        $router->addRoute(new HTTPRouteExample($request, $response, $authorizationDisabled));

        // return
        return $router;
    }
367641
public function getRouterContainer()
    {
        if (null === $this->routerContainer) {
            $this->setRouterContainer(new RouterContainer());
            $this->routerContainer
                ->setMapBuilder([$this->getRouteBuilder(), 'build']);
        }
        return $this->routerContainer;
    }