43 if (!is_int(
$optimizers) ||
$optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) {
52 if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
56 if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->
isStrictVariables() && !$env->
hasExtension(
'Twig_Extension_Sandbox')) {
59 if (
'Twig_Node' !== get_class($node)) {
60 array_unshift($this->prependedNodes, array());
66 $this->inABody =
true;
77 if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
81 if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) {
87 if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->
isStrictVariables() && !$env->
hasExtension(
'Twig_Extension_Sandbox')) {
89 $this->inABody =
false;
90 } elseif ($this->inABody) {
91 if (!$expression &&
'Twig_Node' !== get_class($node) &&
$prependedNodes = array_shift($this->prependedNodes)) {
108 if (
'Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) {
109 $this->prependedNodes[0][] = $node->getAttribute(
'name');
132 $exprNode = $node->getNode(
'expr');
137 $exprNode->setAttribute(
'output',
true);
153 return $node->getNode(
'node');
166 $node->setAttribute(
'with_loop',
false);
167 array_unshift($this->loops, $node);
168 array_unshift($this->loopsTargets, $node->getNode(
'value_target')->getAttribute(
'name'));
169 array_unshift($this->loopsTargets, $node->getNode(
'key_target')->getAttribute(
'name'));
170 } elseif (!$this->loops) {
179 $node->setAttribute(
'always_defined',
true);
185 $node->setAttribute(
'always_defined',
true);
200 &&
'include' === $node->getAttribute(
'name')
201 && (!$node->getNode(
'arguments')->hasNode(
'with_context')
202 ||
false !== $node->getNode(
'arguments')->getNode(
'with_context')->getAttribute(
'value')
211 ||
'parent' === $node->getNode(
'attribute')->getAttribute(
'value')
213 && (
true === $this->loops[0]->getAttribute(
'with_loop')
215 &&
'loop' === $node->getNode(
'node')->getAttribute(
'name')
229 array_shift($this->loops);
230 array_shift($this->loopsTargets);
231 array_shift($this->loopsTargets);
237 $this->loops[0]->setAttribute(
'with_loop',
true);
242 foreach ($this->loops as $loop) {
243 $loop->setAttribute(
'with_loop',
true);
253 class_alias(
'Twig_NodeVisitor_Optimizer',
'Twig\NodeVisitor\OptimizerNodeVisitor',
false);
Represents a node in the AST.
optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env)
Removes "raw" filters.
Represents a node in the AST.
Represents an include node.
getPriority()
Returns the priority for this visitor.
Twig_NodeVisitor_Optimizer tries to optimizes the AST.
optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env)
Represents a block call node.
Abstract class for all nodes that represents an expression.
const OPTIMIZE_VAR_ACCESS
Represents a node that outputs an expression.
__construct($optimizers=-1)
Represents a parent node.
optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes print nodes.
Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2...
enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes "for" tag by removing the "loop" variable creation whenever possible.
hasExtension($class)
Returns true if the given extension is registered.
Represents a block call node.
doLeaveNode(Twig_Node $node, Twig_Environment $env)
Stores the Twig configuration.
doEnterNode(Twig_Node $node, Twig_Environment $env)
leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes "for" tag by removing the "loop" variable creation whenever possible.
isStrictVariables()
Checks if the strict_variables option is enabled.
const OPTIMIZE_RAW_FILTER