/**
  * {@inheritdoc}
  */
 public function register()
 {
     $this->container->registerSingleton([ViewFactory::class, 'view'], function ($container) {
         $app = $container->get('app');
         $applicationPath = $app->getPath();
         $fileSystem = $container->get('fileSystem');
         // Create factory instance
         $factory = new ViewFactory($fileSystem, $applicationPath . '/resources/views', $app->getCharset());
         // Register template renderer
         $factory->registerRenderer('.tpl.php', function () use($applicationPath, $fileSystem) {
             return new Template($fileSystem, $applicationPath . '/storage/cache/views');
         });
         // Return factory instance
         return $factory;
     });
 }
Exemple #2
0
 /**
  * Renders and returns the pagination partial.
  *
  * @access  public
  * @param   string  $view  Pagination view
  * @return  string
  */
 public function render($view)
 {
     if (empty($this->viewFactory)) {
         throw new RuntimeException(vsprintf("%s(): A [ ViewFactory ] instance is required to render pagination views.", [__METHOD__]));
     }
     return $this->viewFactory->create($view, $this->paginate())->render();
 }
 /**
  * Retruns a generic error page.
  *
  * @access  protected
  * @param   boolean    $returnAsJson  Should we return JSON?
  * @return  string
  */
 protected function getGenericError($returnAsJson)
 {
     $code = $this->exception->getCode();
     if ($returnAsJson) {
         switch ($code) {
             case 403:
                 $message = 'You don\'t have permission to access the requested resource.';
                 break;
             case 404:
                 $message = 'The resource you requested could not be found. It may have been moved or deleted.';
                 break;
             case 405:
                 $message = 'The request method that was used is not supported by this resource.';
                 break;
             default:
                 $message = 'An error has occurred while processing your request.';
         }
         return json_encode(['message' => $message]);
     } else {
         $view = 'error';
         if ($this->exception instanceof RequestException) {
             if ($this->view->exists('mako-error::' . $code)) {
                 $view = $code;
             }
         }
         return $this->view->render('mako-error::' . $view);
     }
 }
Exemple #4
0
 /**
  * Return rendered content using mako templates
  *
  * @access  protected
  * @param   string  $view  View path
  * @param   array   $data  View data
  * @return  string
  */
 protected function createView($view, array $data)
 {
     // Create view
     $view = $this->view->create($view, $data);
     // Return rendered view
     return $view->render();
 }
Exemple #5
0
 public function home(ViewFactory $view)
 {
     return $view->create('home');
 }
Exemple #6
0
 /**
  * Welcome route.
  *
  * @access  public
  * @param   \mako\view\ViewFactory  $view  View factory
  * @return  string
  */
 public function index(ViewFactory $view)
 {
     return $view->create('home/index');
 }