mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-18 17:55:23 +00:00
f640320202
* 3.x: (26 commits) Remove the documentation comments compilation overhead Clarify source function trust requirements Throw on PCRE errors in the matches operator Document that reusing a non-rewindable iterator after destructuring is unsupported Release destructuring temporaries after assignment Deprecate prefixed macro definedness checks Fix duplicate macro deprecation wording Throw when list formatting fails Document that sequence destructuring consumes one value per pattern slot Fix the html_attr documentation about iterables in data attributes Warn about untrusted input with the default Tempest markdown converter Document that overriding MacroNode::compile() is not supported anymore Merge overlapping CHANGELOG entries for the destructuring fatal error fix Document that include_only keeps global variables available Remove lazy macro import resolution Honor date formatter prototype calendars Fix Stringable keys for ArrayAccess implementations Fix repeated object destructuring evaluation Restore void return type compatibility for extension points Reject destructuring patterns containing no variables ... # Conflicts: # CHANGELOG # doc/deprecated.rst # doc/filters/format_datetime.rst # extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php # extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php # extra/twig-extra-bundle/TwigExtraBundle.php # src/MacroNamespace.php # src/Node/MacrosNode.php # src/Parser.php # src/Test/IntegrationTestCase.php # src/Test/NodeTestCase.php # tests/CallMacroTest.php # tests/ExpressionParserTest.php # tests/Fixtures/macros/duplicate_definition.legacy.test # tests/Node/MacrosTest.php # tests/ParserTest.php
56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Twig.
|
|
*
|
|
* (c) Fabien Potencier
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Twig\Extension;
|
|
|
|
use Twig\Profiler\NodeVisitor\ProfilerNodeVisitor;
|
|
use Twig\Profiler\Profile;
|
|
|
|
class ProfilerExtension extends AbstractExtension
|
|
{
|
|
/**
|
|
* @var Profile[]
|
|
*/
|
|
private array $actives = [];
|
|
|
|
public function __construct(Profile $profile)
|
|
{
|
|
$this->actives[] = $profile;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function enter(Profile $profile)
|
|
{
|
|
$this->actives[0]->addProfile($profile);
|
|
array_unshift($this->actives, $profile);
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function leave(Profile $profile)
|
|
{
|
|
$profile->leave();
|
|
array_shift($this->actives);
|
|
|
|
if (1 === \count($this->actives)) {
|
|
$this->actives[0]->leave();
|
|
}
|
|
}
|
|
|
|
public function getNodeVisitors(): array
|
|
{
|
|
return [new ProfilerNodeVisitor(static::class)];
|
|
}
|
|
}
|