コード例 #1
0
ファイル: Parser.php プロジェクト: joseym/li3_hierarchy
 /**
  * Parse the template
  * @param  blob 	$source template source code
  * @param  object 	$blocks `BlockSet` object
  * @return [type]         [description]
  */
 public static function parse($blocks, $data, $options)
 {
     $options += array('type' => 'html');
     $cache = new Cache();
     static::$_terminals = array_flip(Lexer::terminals());
     static::$_blocks = $blocks;
     static::$_cacheFile = substr(str_ireplace('/', '_', static::$_blocks->templates(0)), 1);
     $key = static::$_cacheFile . $options['type'];
     $_pattern = "/{:(block) \"({:block})\"(?: \\[(.+)\\])?}(.*){\\1:}/msU";
     static::$_templates = array_reverse($blocks->templates());
     if ($cache->file(sha1($key))) {
         return sha1($key);
     } else {
         $i = 0;
         while ($i < ($count = count(static::$_templates))) {
             if ($i == $count) {
                 break;
             }
             $source = static::_read(static::$_templates[$i]);
             $template = static::_replace($source, $i, $options);
             $i++;
         }
     }
     // final parent template handler
     return static::$_template;
 }
コード例 #2
0
ファイル: Hierarchy.php プロジェクト: joseym/li3_hierarchy
 /**
  * Render the template
  * Uses the final view/template returned from the `Lexer::$_blockSet`
  * @param  string $template full path to template file
  * @param  array  $data     data vars
  * @param  array  $options
  * 
  * @uses Lexer::$_blockSet `BlockSet` returned from templates
  * 
  * @return string           parsed template with block sections replaced
  */
 public function render($template, $data = array(), array $options = array())
 {
     $defaults = array('context' => array(), 'type' => 'html');
     $options += $defaults;
     $this->_context = $options['context'] + $this->_context;
     $this->_data = (array) $data + $this->_vars;
     $template__ = $template;
     // Load pages/layouts
     if (!preg_match("/element/", $template__)) {
         $cache = new Cache();
         // Get all the template blocks
         static::$_blocks = Lexer::run($template__, $data, $options);
         if (gettype(static::$_blocks) == 'object') {
             // parse the template contents, master is the final template
             $cacheFile = Parser::parse(static::$_blocks, $data, $options);
         } else {
             $cacheFile = static::$_blocks;
         }
         $template__ = $cacheFile;
     }
     unset($options, $template, $defaults, $data);
     if ($this->_config['extract']) {
         extract($this->_data, EXTR_OVERWRITE);
     } elseif ($this->_view) {
         extract((array) $this->_view->outputFilters, EXTR_OVERWRITE);
     }
     ob_start();
     include $template__;
     return ob_get_clean();
 }