Пример #1
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     if ($node->hasChild('else')) {
         //extract data to be traversed
         $compiler->indented('$temp = ')->compileNode($node->getChild('source'))->add(';');
         //generate check and code for the 'else' branch
         $compiler->indented('if(empty($temp)) {')->indent()->compileNode($node->getChild('else'))->outdent()->indented('} else {')->indent();
         $source = new TempVariableNode('temp');
     } else {
         $source = $node->getChild('source');
     }
     $compiler->indented('foreach(')->compileNode($source)->add(' as ');
     if ($node->hasChild('loop_key')) {
         $compiler->compileNode($node->getChild('loop_key'))->add(' => ');
     }
     $variables = $node->getData('variables');
     if ($variables === 1) {
         $compiler->compileNode($node->getChild('loop_variable_0'))->add(') {')->indent();
     } else {
         $arguments = [];
         for ($i = 0; $i < $variables; ++$i) {
             $arguments[] = $node->getChild('loop_variable_' . $i);
         }
         $compiler->add('$loopVariable) {')->indent()->indented('list')->compileArgumentList($arguments)->add(' = $loopVariable;');
     }
     $compiler->compileNode($node->getChild('loop_body'))->outdent()->indented('}');
     if ($node->hasChild('else')) {
         //bracket opened after if-empty check
         $compiler->outdent()->indented('}');
     }
 }
Пример #2
0
 public function compile(Compiler $compiler)
 {
     $compiler->add("<?php\n");
     /** @var $childNode ClassNode */
     $childNode = $this->getChild(0);
     if ($childNode->getNameSpace() !== '') {
         $compiler->indented("namespace %s;\n", $childNode->getNameSpace());
     }
     $compiler->indented('use Minty\\Environment;');
     $compiler->indented('use Minty\\Context;');
     $compiler->add("\n");
     parent::compile($compiler);
 }
Пример #3
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     $compiler->indented('switch(')->compileNode($node->getData('tested'))->add(')')->add(' {')->indent();
     foreach ($node->getChildren() as $branch) {
         if (!$branch->hasChild('condition')) {
             $compiler->indented('default:');
         } else {
             $compiler->indented('case ')->compileNode($branch->getChild('condition'))->add(':');
         }
         $compiler->indent()->compileNode($branch->getChild('body'))->indented('break;')->outdent();
     }
     $compiler->outdent()->indented('}');
 }
Пример #4
0
 public function compile(Compiler $compiler)
 {
     if ($compiler->getEnvironment()->getOption('debug')) {
         $compiler->indented('//Line %d: %s tag', $this->getData('line'), $this->tag->getTag());
     }
     $this->tag->compile($compiler, $this);
 }
Пример #5
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     $first = true;
     $else = null;
     foreach ($node->getChildren() as $branch) {
         if ($first) {
             $compiler->indented('if(');
             $first = false;
         } elseif (!$branch->hasChild('condition')) {
             $else = $branch->getChild('body');
             continue;
         } else {
             $compiler->add(' elseif(');
         }
         $compiler->compileNode($branch->getChild('condition'))->add(') {')->indent()->compileNode($branch->getChild('body'))->outdent()->indented('}');
     }
     if ($else !== null) {
         $compiler->add(' else {')->indent()->compileNode($else)->outdent()->indented('}');
     }
 }
Пример #6
0
 public function compile(Compiler $compiler)
 {
     $compiler->indented('')->compileNode($this->getChild('expression'))->add(';');
 }
Пример #7
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     $compiler->indented('ob_start();');
     $compiler->compileNode($node->getChild('body'));
     $compiler->indented('')->compileNode($node->getChild('into'))->add(' = ob_get_clean();');
 }
Пример #8
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     $compiler->indented('unset')->compileArgumentList($node->getChildren())->add(';');
 }
Пример #9
0
 public function compile(Compiler $compiler, TagNode $node)
 {
     $compiler->indented('(new ' . $node->getData('template'))->add('(')->compileNode($node->getChild('environment'))->add('))->displayTemplate(')->compileNode($node->getChild('context'))->add(');');
 }
Пример #10
0
 private function compileBlock(Compiler $compiler, $method, RootNode $body)
 {
     $compiler->indented('public function %s(Context $context)', $method);
     $compiler->indented('{');
     $compiler->indent();
     if (!$body->hasData('environment_accessed') || $body->getData('environment_accessed')) {
         $compiler->indented('$environment = $this->getEnvironment();');
     }
     $compiler->compileNode($body);
     $compiler->outdent();
     $compiler->indented("}\n");
 }