Ejemplo n.º 1
0
 /**
  * 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;
 }