Exemplo n.º 1
0
 protected function parse()
 {
     require_once PHPTAL_DIR . 'PHPTAL/Dom/Parser.php';
     // instantiate the PHPTAL source parser
     $parser = new PHPTAL_Dom_Parser($this->_encoding);
     $parser->stripComments($this->_stripComments);
     $data = $this->_source->getData();
     $realpath = $this->_source->getRealPath();
     if ($this->_prefilter) {
         $data = $this->_prefilter->filter($data);
     }
     $tree = $parser->parseString($data, $realpath);
     require_once PHPTAL_DIR . 'PHPTAL/Php/CodeGenerator.php';
     $generator = new PHPTAL_Php_CodeGenerator($this->getFunctionName(), $this->_source->getRealPath());
     $generator->setEncoding($this->_encoding);
     $generator->setOutputMode($this->_outputMode);
     $generator->generate($tree);
     if (!@file_put_contents($this->_codeFile, $generator->getResult())) {
         throw new PHPTAL_Exception('Unable to open ' . $this->_codeFile . ' for writing');
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * parse currently set template
  * @return string (compiled PHP code)
  */
 protected function parse()
 {
     self::setIncludePath();
     require_once 'PHPTAL/Dom/DocumentBuilder.php';
     require_once 'PHPTAL/Php/CodeGenerator.php';
     self::restoreIncludePath();
     // instantiate the PHPTAL source parser
     $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding);
     $builder = new PHPTAL_Dom_DocumentBuilder();
     $builder->stripComments($this->_stripComments);
     $data = $this->_source->getData();
     $realpath = $this->_source->getRealPath();
     if ($this->_prefilter) {
         $data = $this->_prefilter->filter($data);
     }
     $tree = $parser->parseString($builder, $data, $realpath)->getResult();
     $generator = new PHPTAL_Php_CodeGenerator($this->getFunctionName(), $this->_source->getRealPath(), $this->_encoding, $this->_outputMode, $this->getCodePath());
     $result = $generator->generateCode($tree);
     return $result;
 }