Class Twig_NodeVisitor_Optimizer

InheritanceTwig_NodeVisitor_Optimizer » Twig_BaseNodeVisitor
ImplementsTwig_NodeVisitorInterface

Twig_NodeVisitor_Optimizer tries to optimizes the AST.

This visitor is always the last registered one.

You can configure which optimizations you want to activate via the optimizer mode.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructor. Twig_NodeVisitor_Optimizer
enterNode() {@inheritdoc} Twig_BaseNodeVisitor
getPriority() {@inheritdoc} Twig_NodeVisitor_Optimizer
leaveNode() {@inheritdoc} Twig_BaseNodeVisitor

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addLoopToAll() Twig_NodeVisitor_Optimizer
addLoopToCurrent() Twig_NodeVisitor_Optimizer
doEnterNode() {@inheritdoc} Twig_NodeVisitor_Optimizer
doLeaveNode() {@inheritdoc} Twig_NodeVisitor_Optimizer
enterOptimizeFor() Optimizes "for" tag by removing the "loop" variable creation whenever possible. Twig_NodeVisitor_Optimizer
leaveOptimizeFor() Optimizes "for" tag by removing the "loop" variable creation whenever possible. Twig_NodeVisitor_Optimizer
optimizePrintNode() Optimizes print nodes. Twig_NodeVisitor_Optimizer
optimizeRawFilter() Removes "raw" filters. Twig_NodeVisitor_Optimizer
optimizeVariables() Twig_NodeVisitor_Optimizer

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
OPTIMIZE_ALL -1 Twig_NodeVisitor_Optimizer
OPTIMIZE_FOR 2 Twig_NodeVisitor_Optimizer
OPTIMIZE_NONE 0 Twig_NodeVisitor_Optimizer
OPTIMIZE_RAW_FILTER 4 Twig_NodeVisitor_Optimizer
OPTIMIZE_VAR_ACCESS 8 Twig_NodeVisitor_Optimizer

Property Details

$inABody protected property
protected $inABody false
$loops protected property
protected $loops = []
$loopsTargets protected property
protected $loopsTargets = []
$optimizers protected property
protected $optimizers null
$prependedNodes protected property
protected $prependedNodes = []

Method Details

__construct() public method

Constructor.

public void __construct ( $optimizers = -1 )
$optimizers int

The optimizer mode

addLoopToAll() protected method

protected void addLoopToAll ( )
addLoopToCurrent() protected method

protected void addLoopToCurrent ( )
doEnterNode() protected method

{@inheritdoc}

protected void doEnterNode ( Twig_Node $node, Twig_Environment $env )
$node
$env
doLeaveNode() protected method

{@inheritdoc}

protected void doLeaveNode ( Twig_Node $node, Twig_Environment $env )
$node
$env
enterOptimizeFor() protected method

Optimizes "for" tag by removing the "loop" variable creation whenever possible.

protected void enterOptimizeFor ( Twig_NodeInterface $node, Twig_Environment $env )
$node Twig_NodeInterface

A Node

$env Twig_Environment

The current Twig environment

getPriority() public method

{@inheritdoc}

public void getPriority ( )
leaveOptimizeFor() protected method

Optimizes "for" tag by removing the "loop" variable creation whenever possible.

protected void leaveOptimizeFor ( Twig_NodeInterface $node, Twig_Environment $env )
$node Twig_NodeInterface

A Node

$env Twig_Environment

The current Twig environment

optimizePrintNode() protected method

Optimizes print nodes.

It replaces:

  • "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()"
protected Twig_NodeInterface optimizePrintNode ( Twig_NodeInterface $node, Twig_Environment $env )
$node Twig_NodeInterface

A Node

$env Twig_Environment

The current Twig environment

optimizeRawFilter() protected method

Removes "raw" filters.

protected Twig_NodeInterface optimizeRawFilter ( Twig_NodeInterface $node, Twig_Environment $env )
$node Twig_NodeInterface

A Node

$env Twig_Environment

The current Twig environment

optimizeVariables() protected method

protected void optimizeVariables ( Twig_NodeInterface $node, Twig_Environment $env )
$node
$env