Class yii\twig\Optimizer
Inheritance | yii\twig\Optimizer |
---|---|
Implements | Twig_NodeVisitorInterface |
Source Code | https://github.com/yiisoft/yii2-twig/blob/master/src/Optimizer.php |
Optimizer removes echo before special functions call and injects function name as an argument for the view helper calls.
Public Methods
Method | Description | Defined By |
---|---|---|
enterNode() | yii\twig\Optimizer | |
getPriority() | yii\twig\Optimizer | |
leaveNode() | yii\twig\Optimizer |
Method Details
public void enterNode ( \Twig_Node $node, \Twig_Environment $env ) | ||
$node | ||
$env |
public function enterNode(\Twig_Node $node, \Twig_Environment $env)
{
return $node;
}
public void leaveNode ( \Twig_Node $node, \Twig_Environment $env ) | ||
$node | ||
$env |
public function leaveNode(\Twig_Node $node, \Twig_Environment $env)
{
if ($node instanceof \Twig_Node_Print) {
$expression = $node->getNode('expr');
if ($expression instanceof \Twig_Node_Expression_Function) {
$name = $expression->getAttribute('name');
if (preg_match('/^(?:register_.+_asset|use|.+_begin|.+_end)$/', $name)) {
return new \Twig_Node_Do($expression, $expression->getTemplateLine());
} elseif (in_array($name, ['begin_page', 'end_page', 'begin_body', 'end_body', 'head'])) {
$arguments = [
new \Twig_Node_Expression_Constant($name, $expression->getTemplateLine()),
];
if ($expression->hasNode('arguments') && $expression->getNode('arguments') !== null) {
foreach ($expression->getNode('arguments') as $key => $value) {
if (is_int($key)) {
$arguments[] = $value;
} else {
$arguments[$key] = $value;
}
}
}
$expression->setNode('arguments', new \Twig_Node($arguments));
return new \Twig_Node_Do($expression, $expression->getTemplateLine());
}
}
}
return $node;
}