You are here

public function Twig_NodeVisitor_Optimizer::enterNode in Translation template extractor 6.3

Called before child nodes are visited.

Parameters

Twig_NodeInterface $node The node to visit:

Twig_Environment $env The Twig environment instance:

Return value

Twig_NodeInterface The modified node

Overrides Twig_NodeVisitorInterface::enterNode

File

vendor/Twig/NodeVisitor/Optimizer.php, line 53

Class

Twig_NodeVisitor_Optimizer
Twig_NodeVisitor_Optimizer tries to optimizes the AST.

Code

public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) {
  if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
    $this
      ->enterOptimizeFor($node, $env);
  }
  if (!version_compare(phpversion(), '5.4.0RC1', '>=') && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env
    ->isStrictVariables() && !$env
    ->hasExtension('sandbox')) {
    if ($this->inABody) {
      if (!$node instanceof Twig_Node_Expression) {
        if (get_class($node) !== 'Twig_Node') {
          array_unshift($this->prependedNodes, array());
        }
      }
      else {
        $node = $this
          ->optimizeVariables($node, $env);
      }
    }
    elseif ($node instanceof Twig_Node_Body) {
      $this->inABody = true;
    }
  }
  return $node;
}