コード例 #1
0
ファイル: View.php プロジェクト: pugphp/framework
 /**
  * Render the contents of a view.
  *
  * @param array $vars        Variables to pass to views
  * @param bool  $bypassCache Whether to bypass the cache
  *
  * @return string The rendered HTML
  */
 public function render(array $vars = [], $bypassCache = false)
 {
     // Check the cache
     if ($this->cache && !$bypassCache) {
         if (($content = Cache::get($this->cacheKey())) !== null) {
             return $content;
         }
     }
     $vars = array_merge($this->vars, $vars);
     switch ($this->type) {
         // The view is a markdown file
         case 'md':
         case 'markdown':
             $this->content = $this->renderMarkdown($vars);
             break;
             // The view is a mustache template
         // The view is a mustache template
         case 'mhtml':
         case 'mustache':
             $this->content = $this->renderMustache($vars);
             break;
             // The view is a simple PHP file
         // The view is a simple PHP file
         case 'php':
         default:
             $this->content = $this->renderPhp($vars);
             break;
     }
     $vars = array_merge($this->vars, $vars);
     if ($this->options['layout'] !== null) {
         $vars['content'] = $this->content;
         $this->content = (new self($this->options['layout'], $vars))->render();
     }
     if ($this->cache) {
         Cache::set($this->cacheKey(), $this->content, $this->cache_expiry);
     }
     return $this->content;
 }