Ejemplo n.º 1
0
 public function handle($e)
 {
     $app = App::getInstance();
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     // header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
     if ($app->config('bono.debug') !== true) {
         if (isset($app->response)) {
             $app->response->setStatus(500);
         }
         if (isset($app->theme)) {
             $view = $app->theme->getView();
             $errorTemplate = 'error';
         } else {
             $view = new View();
             $errorTemplate = '../templates/error.php';
             if (is_readable($errorTemplate)) {
                 $view->setTemplatesDirectory('.');
             }
         }
         return $view->display($errorTemplate, array('error' => $e), 500);
     }
     return call_user_func_array(array($app->whoops, Run::EXCEPTION_HANDLER), func_get_args());
 }
Ejemplo n.º 2
0
 /**
  * Render a template
  *
  * Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR
  * callable to render a template whose output is appended to the
  * current HTTP response body. How the template is rendered is
  * delegated to the current View.
  *
  * @param  string $template The name of the template passed into the view's render() method
  * @param  array  $data     Associative array of data made available to the view
  * @param  int    $status   The HTTP response status code to use (optional)
  */
 public function render($template, $data = array(), $status = null)
 {
     if (!is_null($status)) {
         $this->response->status($status);
     }
     $this->view->setTemplatesDirectory($this->config('templates.path'));
     $this->view->appendData($data);
     $this->view->display($template);
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  */
 public function __construct($options)
 {
     $this->app = App::getInstance();
     if (isset($options['view'])) {
         if (is_callable($options['view'])) {
             $view = $options['view'];
             $this->view = $view();
         }
     } else {
         $this->view = new View();
         if (isset($options['partialTemplatePath'])) {
             $partialTemplatePath = $options['partialTemplatePath'];
         } else {
             $partialTemplatePath = dirname(dirname(dirname(dirname(__DIR__)))) . '/partials';
         }
         $this->view->setTemplatesDirectory($partialTemplatePath);
     }
 }
Ejemplo n.º 4
0
 /**
  * Get and/or set the View
  *
  * This method declares the View to be used by the Slim application.
  * If the argument is a string, Slim will instantiate a new object
  * of the same class. If the argument is an instance of View or a subclass
  * of View, Slim will use the argument as the View.
  *
  * If a View already exists and this method is called to create a
  * new View, data already set in the existing View will be
  * transferred to the new View.
  *
  * @param  string|\Slim\View $viewClass The name or instance of a \Slim\View subclass
  * @return \Slim\View
  */
 public function view($viewClass = null)
 {
     if (!is_null($viewClass)) {
         $existingData = is_null($this->view) ? array() : $this->view->getData();
         if ($viewClass instanceof \Slim\View) {
             $this->view = $viewClass;
         } else {
             $this->view = new $viewClass();
         }
         $this->view->appendData($existingData);
         $this->view->setTemplatesDirectory($this->config('templates.path'));
     }
     return $this->view;
 }
Ejemplo n.º 5
0
 public function handle()
 {
     $app = App::getInstance();
     if ($app->config('bono.debug') !== true) {
         if (isset($app->response)) {
             $app->response->setStatus(404);
         }
         if (isset($app->theme)) {
             $view = $app->theme->getView();
             $errorTemplate = 'notFound';
         } else {
             $view = new View();
             $errorTemplate = '../templates/notFound.php';
             if (is_readable($errorTemplate)) {
                 $view->setTemplatesDirectory('.');
             }
         }
         return $view->display($errorTemplate, array(), 404);
     }
     $app->whoops->sendHttpCode(404);
     return call_user_func(array($app->whoops, Run::EXCEPTION_HANDLER), new RuntimeException("404 Resource not found"));
 }
Ejemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 public function setTemplatesDirectory($dir)
 {
     parent::setTemplatesDirectory($dir);
     $this->engine->setLoader(new \Mustache_Loader_FilesystemLoader($this->getTemplatesDirectory()));
     $this->engine->setPartialsLoader(new \Mustache_Loader_FilesystemLoader($this->getTemplatesDirectory() . "/partials"));
 }
Ejemplo n.º 7
0
 public function setTemplatesDirectory($directory)
 {
     parent::setTemplatesDirectory($directory);
     $this->fenomInstance = null;
 }