private function route(RequestInterface $request): ?Route
    {
        $routes = $this->match($request);

        if (empty($routes)) {
            throw new Exception('No route found', Exception::HTTP_NOT_FOUND);
        }

        $route = $this->guard($request, $routes);

        if (empty($route)) {
            throw new Exception('Method not allowed', Exception::HTTP_METHOD_NOT_ALLOWED);
        }

        $route = $this->overlay($route);

        foreach (array_reverse($this->namespaces) as $namespace) {
            $route['namespace'] = $namespace;

            try {
                return new Route(
                    $route['namespace'],
                    $route['module'],
                    $route['controller'],
                    $route['action'],
                    $route['parameters']
                );
            } catch (Exception $e) {
                continue;
            }
        }

        throw new Exception('Invalid controller/action for this route', Exception::HTTP_INTERNAL_SERVER_ERROR);
    }
private function route(RequestInterface $request): ?Route
    {
        $routes = $this->match($request);

        if (empty($routes)) {
            throw new Exception('No route found', Exception::HTTP_NOT_FOUND);
        }

        $route = $this->guard($request, $routes);

        if (empty($route)) {
            throw new Exception('Method not allowed', Exception::HTTP_METHOD_NOT_ALLOWED);
        }

        $route = $this->overlay($route);

        foreach (array_reverse($this->namespaces) as $namespace) {
            $route['namespace'] = $namespace;

            try {
                return new Route(
                    $route['namespace'],
                    $route['module'],
                    $route['controller'],
                    $route['action'],
                    $route['parameters']
                );
            } catch (Exception $e) {
                continue;
            }
        }

        throw new Exception('Invalid controller/action for this route', Exception::HTTP_INTERNAL_SERVER_ERROR);
    }
private function route ( RequestInterface $ request ) : ? Route { $ routes = $ this -> match ( $ request ) ; if ( empty ( $ routes ) ) { throw new Exception ( 'No route found' , Exception :: HTTP_NOT_FOUND ) ; } $ route = $ this -> guard ( $ request , $ routes ) ; if ( empty ( $ route ) ) { throw new Exception ( 'Method not allowed' , Exception :: HTTP_METHOD_NOT_ALLOWED ) ; } $ route = $ this -> overlay ( $ route ) ; foreach ( array_reverse ( $ this -> namespaces ) as $ namespace ) { $ route [ 'namespace' ] = $ namespace ; try { return new Route ( $ route [ 'namespace' ] , $ route [ 'module' ] , $ route [ 'controller' ] , $ route [ 'action' ] , $ route [ 'parameters' ] ) ; } catch ( Exception $ e ) { continue ; } } throw new Exception ( 'Invalid controller/action for this route' , Exception :: HTTP_INTERNAL_SERVER_ERROR ) ; }
Create route from given request

@param \Psr\Http\Message\RequestInterface $request
@throws \Janeiro\Mvc\Exception
@return \Janeiro\Mvc\Route
Create route from given request