43        if (!is_int(
$optimizers) || 
$optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) {
 
   44            throw new InvalidArgumentException(sprintf(
'Optimizer mode "%s" is not valid.', 
$optimizers));
 
   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);
 
  253class_alias(
'Twig_NodeVisitor_Optimizer', 
'Twig\NodeVisitor\OptimizerNodeVisitor', 
false);
 
An exception for terminatinating execution or to throw for unit testing.
Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2....
Stores the Twig configuration.
Twig_NodeVisitor_Optimizer tries to optimizes the AST.
doLeaveNode(Twig_Node $node, Twig_Environment $env)
Called after child nodes are visited.
const OPTIMIZE_VAR_ACCESS
__construct($optimizers=-1)
optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env)
getPriority()
Returns the priority for this visitor.
optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes print nodes.
leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes "for" tag by removing the "loop" variable creation whenever possible.
doEnterNode(Twig_Node $node, Twig_Environment $env)
Called before child nodes are visited.
optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env)
Removes "raw" filters.
enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
Optimizes "for" tag by removing the "loop" variable creation whenever possible.
const OPTIMIZE_RAW_FILTER
Represents a block call node.
Represents a block call node.
Represents a parent node.
Abstract class for all nodes that represents an expression.
Represents an include node.
Represents a node that outputs an expression.
Represents a node in the AST.
Represents a node in the AST.