Файл: upload/core/vendor/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php
Строк: 97
<?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 TwigProfilerNodeVisitor;
use TwigEnvironment;
use TwigNodeBlockNode;
use TwigNodeBodyNode;
use TwigNodeMacroNode;
use TwigNodeModuleNode;
use TwigNodeNode;
use TwigNodeNodes;
use TwigNodeVisitorNodeVisitorInterface;
use TwigProfilerNodeEnterProfileNode;
use TwigProfilerNodeLeaveProfileNode;
use TwigProfilerProfile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
final class ProfilerNodeVisitor implements NodeVisitorInterface
{
private $varName;
public function __construct(
private string $extensionName,
) {
$this->varName = sprintf('__internal_%s', hash(PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName));
}
public function enterNode(Node $node, Environment $env): Node
{
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
{
if ($node instanceof ModuleNode) {
$node->setNode('display_start', new Nodes([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $this->varName), $node->getNode('display_start')]));
$node->setNode('display_end', new Nodes([new LeaveProfileNode($this->varName), $node->getNode('display_end')]));
} elseif ($node instanceof BlockNode) {
$node->setNode('body', new BodyNode([
new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $this->varName),
$node->getNode('body'),
new LeaveProfileNode($this->varName),
]));
} elseif ($node instanceof MacroNode) {
$node->setNode('body', new BodyNode([
new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $this->varName),
$node->getNode('body'),
new LeaveProfileNode($this->varName),
]));
}
return $node;
}
public function getPriority(): int
{
return 0;
}
}