示例#1
0
    function testFunctionsGeneration()
    {
        $state = new PHPTAL_Php_State($this->newPHPTAL());
        $codewriter = new PHPTAL_Php_CodeWriter($state);
        $codewriter->doFunction('test1', '$tpl');
        $codewriter->pushHTML($codewriter->interpolateHTML('test1'));
        $codewriter->doFunction('test2', '$tpl');
        $codewriter->pushHTML('test2');
        $codewriter->doEnd();
        $codewriter->pushHTML('test1');
        $codewriter->doEnd();
        $res = $codewriter->getResult();
        $exp = <<<EOS
<?php function test2(\$tpl) {?>test2<?php}?>
<?php function test1(\$tpl) {?>test1test1<?php}?>
EOS;
        $res = normalize_phpsource($res, true);
        $exp = normalize_phpsource($exp, true);
        $this->assertEquals($exp, $res);
    }
示例#2
0
 /**
  * Parse currently set template, prefilter and generate PHP code.
  *
  * @return string (compiled PHP code)
  */
 protected function parse()
 {
     $data = $this->_source->getData();
     $prefilters = $this->getPreFilterInstances();
     foreach ($prefilters as $prefilter) {
         $data = $prefilter->filter($data);
     }
     $realpath = $this->_source->getRealPath();
     $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding);
     $builder = new PHPTAL_Dom_PHPTALDocumentBuilder();
     $tree = $parser->parseString($builder, $data, $realpath)->getResult();
     foreach ($prefilters as $prefilter) {
         if ($prefilter instanceof PHPTAL_PreFilter) {
             if ($prefilter->filterDOM($tree) !== NULL) {
                 throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()");
             }
         }
     }
     $state = new PHPTAL_Php_State($this);
     $codewriter = new PHPTAL_Php_CodeWriter($state);
     $codewriter->doTemplateFile($this->getFunctionName(), $tree);
     return $codewriter->getResult();
 }
示例#3
0
文件: PHPTAL.php 项目: palmic/lbox
 /**
  * Parse currently set template, prefilter and generate PHP code.
  * 
  * @return string (compiled PHP code)
  */
 protected function parse()
 {
     self::setIncludePath();
     require_once 'PHPTAL/Dom/DocumentBuilder.php';
     require_once 'PHPTAL/Php/State.php';
     require_once 'PHPTAL/Php/CodeWriter.php';
     self::restoreIncludePath();
     // instantiate the PHPTAL source parser
     $data = $this->_source->getData();
     $prefilters = $this->getPreFilterInstances();
     foreach ($prefilters as $prefilter) {
         $data = $prefilter->filter($data);
     }
     $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding);
     $builder = new PHPTAL_Dom_DocumentBuilder();
     $realpath = $this->_source->getRealPath();
     $tree = $parser->parseString($builder, $data, $realpath)->getResult();
     foreach ($prefilters as $prefilter) {
         if ($prefilter instanceof PHPTAL_PreFilter) {
             if ($prefilter->filterDOM($tree)) {
                 throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()");
             }
         }
     }
     $state = new PHPTAL_Php_State($this);
     $codewriter = new PHPTAL_Php_CodeWriter($state);
     $codewriter->doTemplateFile($this->getFunctionName(), $tree);
     return $codewriter->getResult();
 }