예제 #1
0
 public function compile(Compiler $compiler)
 {
     $compiler->write('$this->set( $context , ')->raw('["' . implode('","', $this->convertToRoute($this->getAttribute(self::ATTR_VARIABLE))) . '"]')->raw(' , function() use ( $context ) {' . "\n")->indent();
     if ($this->getAttribute(self::ATTR_IS_BLOCK)) {
         $compiler->writeln('ob_start();')->subcompile($this->getNode(self::NODE_VALUE))->writeln('return ob_get_clean();');
     } else {
         $compiler->write('return ')->subcompile($this->getNode(self::NODE_VALUE))->raw(';' . "\n");
     }
     $compiler->outdent()->writeln('});' . "\n");
 }
예제 #2
0
 protected function renderBody(Compiler $compiler)
 {
     $compiler->writeln('public function __construct( $env ) {')->indent()->writeln('parent::__construct( $env );');
     if ($this->hasParent()) {
         $compiler->writeln('// Line ' . $this->getNode(self::NODE_PARENT)->getLineNo())->writeln('$this->parent = $env->loadTemplate( $this->getParent() );');
     }
     $compiler->writeln('$this->blocks = [')->indent();
     foreach ($this->getBlocks() as $block) {
         $compiler->write('')->string($block->getName())->raw("\t\t=>\t[ \$this , ")->string($block->getMethodName())->raw(" ],\n");
     }
     $compiler->outdent()->writeln('];');
     $compiler->outdent()->writeln('}')->line();
     $compiler->writeln('/**')->writeln(' * Render template')->writeln(' * @param array $context')->writeln(' */')->writeln('public function display( array $context = [] , array $blocks = [] ) {')->indent();
     if ($this->hasParent()) {
         foreach ($this->getBody()->getNodes() as $node) {
             if (!$node instanceof PrintNode) {
                 $node->compile($compiler);
             }
         }
         $compiler->writeln('$this->parent->display( $context , array_merge( $this->blocks , $blocks ) );');
     } else {
         $this->getBody()->compile($compiler);
     }
     $compiler->outdent()->writeln('}')->line();
 }
예제 #3
0
 public function compile(Compiler $compiler)
 {
     $args = $this->getNode(self::NODE_ARGS)->getNodes();
     $macroName = $this->getAttribute(self::ATTR_NAME);
     $compiler->writeln('// Line ' . $this->getLineNo())->write('public function macro_' . $macroName)->scopeIn(Compiler::SCOPE_MACRO, $macroName)->raw('( $context = [] , $arguments = [] ) {')->line()->indent()->writeln('$args = [')->indent();
     foreach ($args as $name => $value) {
         $compiler->write('')->string($name)->raw(' => ');
         if ($value) {
             $compiler->subcompile($value);
         } else {
             $compiler->raw('null');
         }
         $compiler->raw(',')->line();
     }
     $compiler->outdent()->writeln('];')->writeln('$context = array_merge( $context , $this->prepareArgs( $args , $arguments ) );')->subcompile($this->getNode(self::NODE_BODY))->scopeOut()->outdent()->writeln('}');
 }
예제 #4
0
 public function compile(Compiler $compiler)
 {
     /** @var Node[] $tests */
     $tests = $this->getNode(self::NODE_TESTS);
     for ($i = 0; $i < count($tests); $i += 2) {
         $test = $tests[$i];
         $true = $tests[$i + 1];
         if ($i == 0) {
             $compiler->write('if ( ');
         } else {
             $compiler->raw(' elseif ( ');
         }
         $compiler->subcompile($test)->raw(' ) { ' . "\n")->indent()->subcompile($true)->outdent()->write('}');
     }
     if ($this->hasNode(self::NODE_ELSE)) {
         $compiler->raw(' else { ' . "\n")->indent()->subcompile($this->getNode(self::NODE_ELSE))->outdent()->write('}');
     }
     $compiler->line();
 }
예제 #5
0
 public function compile(Compiler $compiler)
 {
     $compiler->write('echo ');
     $this->getNode(self::NODE_EXPRESSION)->compile($compiler);
     $compiler->raw(';')->line();
 }
예제 #6
0
 public function compile(Compiler $compiler)
 {
     $compiler->write('echo ')->string($this->getAttribute('text'))->raw(";\n");
 }