Example #1
0
 public function renderView($path, $vars = array())
 {
     // Create empty controller and inject services to it
     $controller = new Controller();
     $controller->setServiceContainer($this->services);
     // Create and display the response
     $response = $controller->render($path, $vars);
     echo $response->getContent() . "\n";
 }
Example #2
0
 public function createResponse($exception)
 {
     // Create empty controller and inject services to it
     $controller = new Controller();
     $controller->setServiceContainer($this->services);
     // Create special response for exceptions
     $view = $this->getExceptionView(get_class($exception));
     $message = $exception->getMessage();
     $config = $this->get('config')->data;
     return $controller->render($view, compact('message', 'config'), 'html', array(), 500);
 }
Example #3
0
 public function run($request)
 {
     $response = null;
     // Authorize
     $authorized = $this->services->get('firewall')->canAccessPath($request->getRoute());
     if ($authorized) {
         // Find the matching action and run it
         $router = $this->services->get('router');
         $actionName = $router->getActionName($request->getRoute());
         if ($actionName) {
             $response = $this->runAction($actionName);
         } else {
             // Create empty controller and inject services to it
             $controller = new Controller();
             $controller->setServiceContainer($this->services);
             // If it's the first time application's run, open installation wizard
             $config = $this->services->get('config');
             $appSettings = $config->data['appSettings'];
             if (empty($appSettings['installed']) && empty($config->data['superPass'])) {
                 // Redirect
                 $response = $controller->redirect('Install:index');
             } else {
                 // Create the "Not Found" HTTP response
                 $this->services->get('logger')->info('Route /' . $request->getRoute() . ' not found');
                 $response = $controller->render('error/404.html.php', array(), 'html', array(), 404);
             }
         }
     } else {
         /*
         // Return the "Access denided" HTTP response
         
         return new Response('Access denied (' . $request->getRoute() . ')', null, 403);
         */
         // Redirect to the login page
         $loginAction = $this->services->get('firewall')->getLoginAction();
         $loginPath = '?' . $this->services->get('router')->getRoute($loginAction);
         $response = new Response('', array(array('Location', $loginPath)), 303);
     }
     // Clean
     $this->services->clean();
     // Return the response
     return $response;
 }