Ouzo\Routing\Router::findRoute PHP Method

findRoute() public method

public findRoute ( ) : RouteRule
return RouteRule
    public function findRoute()
    {
        $path = $this->uri->getPathWithoutPrefix();
        $requestType = Uri::getRequestType();
        $rule = $this->findRouteRule($path, $requestType);
        if (!$rule) {
            throw new RouterException('No route rule found for HTTP method [' . $requestType . '] and URI [' . $path . ']');
        }
        $rule->setParameters($path);
        return $rule;
    }

Usage Example

Exemplo n.º 1
0
 public function init()
 {
     $uri = new Uri();
     $router = new Router($uri);
     $routeRule = $router->findRoute();
     $this->currentController = $routeRule->getController();
     $this->requestContext->setCurrentController($this->currentController);
     $this->currentAction = $routeRule->isActionRequired() ? $routeRule->getAction() : $uri->getAction();
     $this->sessionInitializer->startSession();
     $this->currentControllerObject = $this->controllerFactory->createController($routeRule);
     $this->requestContext->setCurrentControllerObject($this->currentControllerObject);
     $this->_logRequest();
     $afterInitCallback = Config::getValue('callback', 'afterControllerInit');
     if ($afterInitCallback) {
         Functions::call($afterInitCallback, array());
     }
     try {
         ob_start();
         $this->_invokeControllerMethods();
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
     ob_end_flush();
 }