Пример #1
0
 /**
  * Parses the tokens
  *
  * @param array $tokens
  *
  * @throws \Liquid\LiquidException
  */
 public function parse(array &$tokens)
 {
     if ($this->fileSystem === null) {
         throw new LiquidException("No file system");
     }
     // read the source of the template and create a new sub document
     $source = $this->fileSystem->readTemplateFile($this->templateName);
     // tokens in this new document
     $maintokens = Template::tokenize($source);
     $eRegexp = new Regexp('/^' . Liquid::get('TAG_START') . '\\s*extends (.*)?' . Liquid::get('TAG_END') . '$/');
     foreach ($maintokens as $maintoken) {
         if ($eRegexp->match($maintoken)) {
             $m = $eRegexp->matches[1];
             break;
         }
     }
     if (isset($m)) {
         $rest = array_merge($maintokens, $tokens);
     } else {
         $childtokens = $this->findBlocks($tokens);
         $blockstartRegexp = new Regexp('/^' . Liquid::get('TAG_START') . '\\s*block (\\w+)\\s*(.*)?' . Liquid::get('TAG_END') . '$/');
         $blockendRegexp = new Regexp('/^' . Liquid::get('TAG_START') . '\\s*endblock\\s*?' . Liquid::get('TAG_END') . '$/');
         $name = null;
         $rest = array();
         $aufzeichnen = false;
         for ($i = 0; $i < count($maintokens); $i++) {
             if ($blockstartRegexp->match($maintokens[$i])) {
                 $name = $blockstartRegexp->matches[1];
                 if (isset($childtokens[$name])) {
                     $aufzeichnen = true;
                     array_push($rest, $maintokens[$i]);
                     foreach ($childtokens[$name] as $item) {
                         array_push($rest, $item);
                     }
                 }
             }
             if (!$aufzeichnen) {
                 array_push($rest, $maintokens[$i]);
             }
             if ($blockendRegexp->match($maintokens[$i]) && $aufzeichnen === true) {
                 $aufzeichnen = false;
                 array_push($rest, $maintokens[$i]);
             }
         }
     }
     $this->hash = md5($source);
     $cache = Template::getCache();
     if (isset($cache)) {
         if (($this->document = $cache->read($this->hash)) != false && $this->document->checkIncludes() != true) {
         } else {
             $this->document = new Document($rest, $this->fileSystem);
             $cache->write($this->hash, $this->document);
         }
     } else {
         $this->document = new Document($rest, $this->fileSystem);
     }
 }
Пример #2
0
 /**
  * Parses the tokens
  *
  * @param array $tokens
  *
  * @throws \Liquid\LiquidException
  */
 public function parse(array &$tokens)
 {
     if ($this->fileSystem === null) {
         throw new LiquidException("No file system");
     }
     // read the source of the template and create a new sub document
     $source = $this->fileSystem->readTemplateFile($this->templateName);
     $this->hash = md5($source);
     $cache = Template::getCache();
     if (isset($cache)) {
         if (($this->document = $cache->read($this->hash)) != false && $this->document->checkIncludes() != true) {
         } else {
             $templateTokens = Template::tokenize($source);
             $this->document = new Document($templateTokens, $this->fileSystem);
             $cache->write($this->hash, $this->document);
         }
     } else {
         $templateTokens = Template::tokenize($source);
         $this->document = new Document($templateTokens, $this->fileSystem);
     }
 }