/** * {@inheritdoc} */ protected function doLeaveNode(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env) { if ($node instanceof Apishka_Templater_Node_Module) { $varName = $this->getVarName(); $node->setNode('display_start', Apishka_Templater_Node::apishka(array(new Apishka_Templater_Profiler_Node_EnterProfile($this->extensionName, Apishka_Templater_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start')))); $node->setNode('display_end', Apishka_Templater_Node::apishka(array(new Apishka_Templater_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')))); } elseif ($node instanceof Apishka_Templater_Node_Block) { $varName = $this->getVarName(); $node->setNode('body', Apishka_Templater_Node_Body::apishka(array(new Apishka_Templater_Profiler_Node_EnterProfile($this->extensionName, Apishka_Templater_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), new Apishka_Templater_Profiler_Node_LeaveProfile($varName)))); } return $node; }
public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) { $this->usedFilters = $usedFilters; $this->usedTags = $usedTags; $this->usedFunctions = $usedFunctions; parent::__construct(); }
public function __construct(Apishka_Templater_Node_Expression_AssignName $keyTarget, Apishka_Templater_Node_Expression_AssignName $valueTarget, Apishka_Templater_Node_ExpressionAbstract $seq, Apishka_Templater_Node_ExpressionAbstract $ifexpr = null, Apishka_Templater_NodeAbstract $body, Apishka_Templater_NodeAbstract $else = null, $lineno, $tag = null) { $body = Apishka_Templater_Node::apishka(array($body, $this->loop = Apishka_Templater_Node_ForLoop::apishka($lineno, $tag))); if (null !== $ifexpr) { $body = Apishka_Templater_Node_If::apishka(Apishka_Templater_Node::apishka(array($ifexpr, $body)), null, $lineno, $tag); } parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag); }
private function checkLoopUsageBody(Apishka_Templater_TokenStream $stream, Apishka_Templater_NodeAbstract $node) { if ($node instanceof Apishka_Templater_Node_Expression_GetAttr && $node->getNode('node') instanceof Apishka_Templater_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { $attribute = $node->getNode('attribute'); if ($attribute instanceof Apishka_Templater_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) { throw new Apishka_Templater_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename()); } } // should check for parent.loop.XXX usage if ($node instanceof Apishka_Templater_Node_For) { return; } foreach ($node as $n) { if (!$n) { continue; } $this->checkLoopUsageBody($stream, $n); } }
public function __construct($capture, Apishka_Templater_NodeAbstract $names, Apishka_Templater_NodeAbstract $values, $lineno, $tag = null) { parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag); /* * Optimizes the node when capture is used for a large block of text. * * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Apishka_Templater_Markup("foo"); */ if ($this->getAttribute('capture')) { $this->setAttribute('safe', true); $values = $this->getNode('values'); if ($values instanceof Apishka_Templater_Node_Text) { $this->setNode('values', Apishka_Templater_Node_Expression_Constant::apishka($values->getAttribute('data'), $values->getLine())); $this->setAttribute('capture', false); } } }
public function __construct(Apishka_Templater_Node_ExpressionAbstract $expr, $lineno, $tag = null) { parent::__construct(array('expr' => $expr), array(), $lineno, $tag); }
public function __construct(Apishka_Templater_NodeAbstract $body, Apishka_Templater_Node_ExpressionAbstract $parent = null, Apishka_Templater_NodeAbstract $blocks, Apishka_Templater_NodeAbstract $macros, Apishka_Templater_NodeAbstract $traits, $embeddedTemplates, $filename) { // embedded templates are set as attributes so that they are only visited once by the visitors parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits, 'display_start' => Apishka_Templater_Node::apishka(), 'display_end' => Apishka_Templater_Node::apishka(), 'constructor_start' => Apishka_Templater_Node::apishka(), 'constructor_end' => Apishka_Templater_Node::apishka(), 'class_end' => Apishka_Templater_Node::apishka()), array('filename' => $filename, 'index' => null, 'embedded_templates' => $embeddedTemplates), 1); }
public function __construct($value, Apishka_Templater_NodeAbstract $body, $lineno, $tag = 'autoescape') { parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag); }
private function filterBodyNodes(Apishka_Templater_NodeAbstract $node) { // check that the body does not contain non-empty output nodes if ($node instanceof Apishka_Templater_Node_Text && !ctype_space($node->getAttribute('data')) || !$node instanceof Apishka_Templater_Node_Text && !$node instanceof Apishka_Templater_Node_BlockReference && $node instanceof Apishka_Templater_NodeOutputInterface) { if (false !== strpos((string) $node, chr(0xef) . chr(0xbb) . chr(0xbf))) { throw new Apishka_Templater_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node->getLine(), $this->getFilename()); } throw new Apishka_Templater_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename()); } // bypass "set" nodes as they "capture" the output if ($node instanceof Apishka_Templater_Node_Set) { return $node; } if ($node instanceof Apishka_Templater_NodeOutputInterface) { return; } foreach ($node as $k => $n) { if (null !== $n && null === $this->filterBodyNodes($n)) { $node->removeNode($k); } } return $node; }
public function __construct($name, Apishka_Templater_NodeAbstract $body, $lineno, $tag = null) { parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag); }
public function enterNode(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env) { if ($node instanceof Apishka_Templater_Node_Expression_GetAttr) { $node->setAttribute('disable_c_ext', true); } return $node; }
public function __construct($extensionName, $type, $name, $varName) { parent::__construct(array(), array('extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName)); }
public function __construct($varName) { parent::__construct(array(), array('var_name' => $varName)); }
public function __construct($data, $lineno) { parent::__construct(array(), array('data' => $data), $lineno); }
public function __construct($lineno, $tag = null) { parent::__construct(array(), array('with_loop' => false, 'ifexpr' => false, 'else' => false), $lineno, $tag); }
/** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. * * @param Apishka_Templater_Node $node A Node * @param Apishka_Templater_Environment $env The current Twig environment */ private function enterOptimizeFor(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env) { if ($node instanceof Apishka_Templater_Node_For) { // disable the loop variable by default $node->setAttribute('with_loop', false); array_unshift($this->loops, $node); array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); } elseif (!$this->loops) { // we are outside a loop return; } elseif ($node instanceof Apishka_Templater_Node_Expression_Name && 'loop' === $node->getAttribute('name')) { $node->setAttribute('always_defined', true); $this->addLoopToCurrent(); } elseif ($node instanceof Apishka_Templater_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) { $node->setAttribute('always_defined', true); } elseif ($node instanceof Apishka_Templater_Node_BlockReference || $node instanceof Apishka_Templater_Node_Expression_BlockReference) { $this->addLoopToCurrent(); } elseif ($node instanceof Apishka_Templater_Node_Expression_Function && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value'))) { $this->addLoopToAll(); } elseif ($node instanceof Apishka_Templater_Node_Expression_GetAttr && (!$node->getNode('attribute') instanceof Apishka_Templater_Node_Expression_Constant || 'parent' === $node->getNode('attribute')->getAttribute('value')) && (true === $this->loops[0]->getAttribute('with_loop') || $node->getNode('node') instanceof Apishka_Templater_Node_Expression_Name && 'loop' === $node->getNode('node')->getAttribute('name'))) { $this->addLoopToAll(); } }
private function getEscaperFilter($type, Apishka_Templater_NodeAbstract $node) { $line = $node->getLine(); $name = Apishka_Templater_Node_Expression_Constant::apishka('escape', $line); $args = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_Constant::apishka((string) $type, $line), Apishka_Templater_Node_Expression_Constant::apishka(null, $line), Apishka_Templater_Node_Expression_Constant::apishka(true, $line))); return Apishka_Templater_Node_Expression_Filter::apishka($node, $name, $args, $line); }
/** * Adds debugging information. * * @param Apishka_Templater_Node $node The related twig node * * @return Apishka_Templater_Compiler The current compiler instance */ public function addDebugInfo(Apishka_Templater_NodeAbstract $node) { if ($node->getLine() != $this->_last_line) { $this->write(sprintf("// line %d\n", $node->getLine())); // when mbstring.func_overload is set to 2 // mb_substr_count() replaces substr_count() // but they have different signatures! if ((int) ini_get('mbstring.func_overload') & 2) { // this is much slower than the "right" version $this->_source_line += mb_substr_count(mb_substr($this->_source, $this->_source_offset), "\n"); } else { $this->_source_line += substr_count($this->_source, "\n", $this->_source_offset); } $this->_source_offset = strlen($this->_source); $this->_debug_info[$this->_source_line] = $node->getLine(); $this->_last_line = $node->getLine(); } return $this; }
/** * Do leave node is safe all * * @param Apishka_Templater_NodeAbstract $node * * @return bool */ protected function doLeaveNodeIsSafeAll($node) { return $node->isSafeAll(); }
public function __construct(Apishka_Templater_NodeAbstract $tests, Apishka_Templater_NodeAbstract $else = null, $lineno, $tag = null) { parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag); }
public function __construct($name, $lineno, $tag = null) { parent::__construct(array(), array('name' => $name), $lineno, $tag); }