Class yii\twig\Optimizer

Inheritanceyii\twig\Optimizer
ImplementsTwig\NodeVisitor\NodeVisitorInterface
Source Code https://github.com/yiisoft/yii2-twig/blob/master/Optimizer.php

Optimizer removes echo before special functions call and injects function name as an argument for the view helper calls.

Method Details

Hide inherited methods

enterNode() public method

public void enterNode ( \Twig\Node\Node $node, \Twig\Environment $env )
$node
$env

                public function enterNode(Node $node, Environment $env): Node
{
    return $node;
}

            
getPriority() public method

public void getPriority ( )

                public function getPriority()
{
    return 100;
}

            
leaveNode() public method

public void leaveNode ( \Twig\Node\Node $node, \Twig\Environment $env )
$node
$env

                public function leaveNode(Node $node, Environment $env): ?Node
{
    if ($node instanceof PrintNode) {
        $expression = $node->getNode('expr');
        if ($expression instanceof FunctionExpression) {
            $name = $expression->getAttribute('name');
            if (preg_match('/^(?:register_.+_asset|use|.+_begin|.+_end)$/', $name)) {
                return new DoNode($expression, $expression->getTemplateLine());
            } elseif (in_array($name, ['begin_page', 'end_page', 'begin_body', 'end_body', 'head'])) {
                $arguments = [
                    new ConstantExpression($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 Node($arguments));
                return new DoNode($expression, $expression->getTemplateLine());
            }
        }
    }
    return $node;
}