Example #1
0
 /**
  * Creates a controller instance
  * @static
  * @final
  * @param Cognosys\Request $request
  * @param Cognosys\Response $response
  * @param array $database_params
  * @param Cognosys\Templates\Decorator
  * @return Cognosys\Controller
  * @throws Exceptions\UserError if the controller name is unknown
  */
 public static final function factory(Request $request, Response $response, array $database_params)
 {
     $cog = $response->cog();
     $controller = $response->controller();
     $action = $response->action();
     $params = $response->params();
     $session = Session::instance();
     if ($cog === null) {
         throw new UserError("There is no such area: <em>{$response->originalController()}</em>");
     }
     // use the namespace inside the application
     $controller_class = "App\\Cogs\\{$cog}\\Controllers\\{$controller}";
     // renders the view even if there is no action
     $instance = new $controller_class($database_params);
     $instance->_request = $request;
     $instance->_response = $response;
     $instance->_session = $session;
     $instance->_view = View::forController($request, $response);
     $instance->_user = $instance->repo(User::classname())->find($session->get('user', false));
     $instance->params = $instance->_getPost();
     //LOW: require all models to use in instanceof?
     return $instance;
 }