CoreFiles by mySites.guru
MeasureTwigNode.php50 lines, 1,365 bytes, from Joomla_5.2.3-Stable-Full_Package.zip
Raw History Compare with 5.2.2
md5
6a1e90468809b2f6516bd856b2c476a8
sha1
54dd3d8d985a5712253eabd15a0dc9f9f5e6ee73
sha256
8087678eb5a36617e37ba7642053dc5cb9f39d01b1320831579fe480caf33881
<?php

namespace DebugBar\Bridge\Twig;

use DebugBar\Bridge\Twig\MeasureTwigExtension;
use Twig\Compiler;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Node;

/**
 * Represents a measure node.
 * Based on Symfony\Bridge\Twig\Node\StopwatchNode
 */
class MeasureTwigNode extends Node
{
    /**
     * @var string
     */
    protected $extName;

    public function __construct(
        Node $name,
        $body,
        AssignNameExpression $var,
        $lineno = 0,
        $tag = null,
        $extName = null
    ) {
        parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
        $this->extName = $extName ?: MeasureTwigExtension::class;
    }

    public function compile(Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->write('')
            ->subcompile($this->getNode('var'))
            ->raw(' = ')
            ->subcompile($this->getNode('name'))
            ->write(";\n")
            ->write("\$this->env->getExtension('".$this->extName."')->startMeasure(")
            ->subcompile($this->getNode('var'))
            ->raw(");\n")
            ->subcompile($this->getNode('body'))
            ->write("\$this->env->getExtension('".$this->extName."')->stopMeasure(")
            ->subcompile($this->getNode('var'))
            ->raw(");\n");
    }
}

The same content is in 22 releases, Joomla 5.2.0-alpha2 to 5.3.0-alpha3. See them all, or every version of this file.