Ouzo\ControllerFactory::createController PHP Method

createController() public method

public createController ( RouteRule $routeRule )
$routeRule Ouzo\Routing\RouteRule
    public function createController(RouteRule $routeRule)
    {
        $controllerName = ClassName::pathToFullyQualifiedName($routeRule->getController());
        foreach ($this->controllerNamespaces as $controllerNamespace) {
            $controller = $controllerNamespace . $controllerName . "Controller";
            if (class_exists($controller)) {
                return $this->getInstance($routeRule, $controller);
            }
        }
        throw new ControllerNotFoundException('Controller [' . $controllerName . '] for URI [' . $routeRule->getUri() . '] does not exist!');
    }

Usage Example

Beispiel #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();
 }