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); }
public function compile(Compiler $compiler, OperatorNode $node) { $operand = $node->getChild(OperatorNode::OPERAND_LEFT); if ($this->isPropertyAccessOperator($operand)) { $root = $operand; while ($this->isPropertyAccessOperator($root)) { $root = $root->getChild(OperatorNode::OPERAND_LEFT); } if ($root instanceof VariableNode) { $compiler->add('isset(')->compileNode($root)->add(') && '); } $operand->addData('mode', 'has'); $operand->compile($compiler); } elseif ($operand instanceof ArrayIndexNode) { $variable = $operand->getChild('identifier'); $keys = [$operand->getChild('key')]; while ($variable instanceof ArrayIndexNode) { /** @var $right OperatorNode */ $keys[] = $variable->getChild('key'); $variable = $variable->getChild('identifier'); } $arguments = [$variable, array_reverse($keys)]; $compiler->add('isset(')->compileNode($variable)->add(') && $context->hasProperty')->compileArgumentList($arguments); } else { $compiler->add('isset(')->compileNode($operand)->add(')'); } }
public function compile(Compiler $compiler, TemplateFunction $function, array $arguments) { if (count($arguments) !== 2) { throw new \InvalidArgumentException('Default function needs two arguments.'); } $compiler->add('(isset(')->compileNode($arguments[0])->add(') ? ')->compileNode($arguments[0])->add(' : ')->compileNode($arguments[1])->add(')'); }
public function compile(Compiler $compiler, OperatorNode $node) { //if(sign($left) != sign($right)) $compiler->add('((')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' < 0 && ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' > 0) || (')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' < 0 && ')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' > 0)'); //then $right + $left % right $compiler->add(' ? (')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' + ')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(')'); //else $left % $right $compiler->add(': (')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add('))'); }
public function compile(Compiler $compiler) { $name = $this->getData('name'); if ($name === '_self') { $compiler->add('$this'); } else { $compiler->add('$context->' . $name); } }
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('}'); } }
public function compile(Compiler $compiler, OperatorNode $node) { $left = $node->getChild(OperatorNode::OPERAND_LEFT); $keys = [$node->getChild(OperatorNode::OPERAND_RIGHT)]; while ($this->isPropertyAccessOperator($left)) { /** @var $left OperatorNode */ $keys[] = $left->getChild(OperatorNode::OPERAND_RIGHT); $left = $left->getChild(OperatorNode::OPERAND_LEFT); } $arguments = [$left, array_reverse($keys)]; if ($node->hasChild(OperatorNode::OPERAND_MIDDLE)) { $arguments[] = $node->getChild(OperatorNode::OPERAND_MIDDLE); } $compiler->add('$context->' . $this->getMethodName($node))->compileArgumentList($arguments); }
public function compile(Compiler $compiler) { if ($this->getObject()) { $compiler->compileNode($this->getObject())->add('->' . $this->getData('name'))->compileArgumentList($this->arguments); } else { $environment = $compiler->getEnvironment(); $function = $environment->getFunction($this->getData('name')); if ($function->getOption('needs_environment')) { array_unshift($this->arguments, new TempVariableNode('environment')); } if ($function->getOption('needs_context')) { array_unshift($this->arguments, new TempVariableNode('context')); } $environment->getFunctionCompiler($function->getOption('compiler'))->compile($compiler, $function, $this->arguments); } }
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('}'); } }
private function compileTemplate($template) { if (!isset($this->compiler)) { $this->initializeCompiler(); } $templateSource = $this->getSource($template); $stream = $this->tokenizer->tokenize($templateSource); $node = $this->parser->parseTemplate($stream, $template); $this->nodeTreeTraverser->traverse($node); return $this->compiler->compile($node); }
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); }
public function compile(Compiler $compiler) { $compiler->add('['); for ($i = 0; $i < $this->itemCount; ++$i) { if ($i !== 0) { $compiler->add(', '); } if ($this->hasChild('key_' . $i)) { $compiler->compileNode($this->getChild('key_' . $i)); $compiler->add(' => '); } $compiler->compileNode($this->getChild('value_' . $i)); } $compiler->add(']'); }
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('}'); }
public function compile(Compiler $compiler) { $compiler->indented('')->compileNode($this->getChild('expression'))->add(';'); }
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"); }
public function compile(Compiler $compiler, OperatorNode $node) { $compiler->add('!'); parent::compile($compiler, $node); }
public function compile(Compiler $compiler) { $compiler->add('$' . $this->getData('name')); }
public function compile(Compiler $compiler, OperatorNode $node) { $compiler->compileNode(new FunctionNode($this->getFunctionName(), $node->getChildren())); }
public function compile(Compiler $compiler) { $compiler->compileData($this->value); }
public function compile(Compiler $compiler, OperatorNode $node) { $compiler->add('(--')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(')'); }
public function compile(Compiler $compiler) { $compiler->compileNode($this->getChild('identifier'))->add('[')->compileNode($this->getChild('key'))->add(']'); }
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();'); }
public function compile(Compiler $compiler) { $compiler->compileString($this->getData('name')); }
public function compile(Compiler $compiler, TagNode $node) { $compiler->indented('unset')->compileArgumentList($node->getChildren())->add(';'); }
public function compile(Compiler $compiler, OperatorNode $node) { $compiler->add('(')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % 2 == 0)'); }
public function compile(Compiler $compiler, TagNode $node) { $compiler->compileNode($node->getChild('body')); }
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(');'); }
public function compile(Compiler $compiler, OperatorNode $node) { $compiler->add('range(')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(', ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' - 1)'); }
public function compile(Compiler $compiler) { foreach ($this->getChildren() as $node) { $compiler->compileNode($node); } }