CoreFiles by mySites.guru
MeasureTwigExtension.php77 lines, 1,669 bytes, from Joomla_5.2.2-Stable-Full_Package.zip
Raw History Compare with 5.2.1
md5
c1301e4e88e01f8a1f6505af0fe8c134
sha1
85d5d3529de3a06733f7405b9b97e8d9c48c91ce
sha256
7650681033dac8631b7364a0d2650ab059916af6871c46b3218178730fa9f37d
<?php

namespace DebugBar\Bridge\Twig;

use Twig\Extension\AbstractExtension;

/**
 * Access debugbar timeline measure in your Twig templates.
 * Based on Symfony\Bridge\Twig\Extension\StopwatchExtension
 *
 * @package DebugBar\Bridge\Twig
 */
class MeasureTwigExtension extends AbstractExtension
{
    /**
     * @var \DebugBar\DataCollector\TimeDataCollector|null
     */
    protected $timeCollector;

    /**
     * @var string
     */
    protected $tagName;

    /**
     * Create a new auth extension.
     *
     * @param \DebugBar\DataCollector\TimeDataCollector|null $debugbar
     * @param string $tagName
     */
    public function __construct($timeCollector, $tagName = 'measure')
    {
        $this->timeCollector = $timeCollector;
        $this->tagName = $tagName;
    }

    /**
     * {@inheritDoc}
     */
    public function getName()
    {
        return static::class;
    }

    /**
     * @return \Twig\TokenParser\TokenParserInterface[]
     */
    public function getTokenParsers()
    {
        return [
            /*
             * {% measure foo %}
             * Some stuff which will be recorded on the timeline
             * {% endmeasure %}
             */
            new MeasureTwigTokenParser(!is_null($this->timeCollector), $this->tagName, $this->getName()),
        ];
    }

    public function startMeasure(...$arg)
    {
        if (!$this->timeCollector) {
            return;
        }

        $this->timeCollector->startMeasure(...$arg);
    }

    public function stopMeasure(...$arg)
    {
        if (!$this->timeCollector) {
            return;
        }

        $this->timeCollector->stopMeasure(...$arg);
    }
}

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.