Security update to Drupal 8.4.6
[yaffs-website] / vendor / twig / twig / lib / Twig / Profiler / NodeVisitor / Profiler.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * @author Fabien Potencier <fabien@symfony.com>
14  *
15  * @final
16  */
17 class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor
18 {
19     private $extensionName;
20
21     public function __construct($extensionName)
22     {
23         $this->extensionName = $extensionName;
24     }
25
26     protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
27     {
28         return $node;
29     }
30
31     protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
32     {
33         if ($node instanceof Twig_Node_Module) {
34             $varName = $this->getVarName();
35             $node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start'))));
36             $node->setNode('display_end', new Twig_Node(array(new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end'))));
37         } elseif ($node instanceof Twig_Node_Block) {
38             $varName = $this->getVarName();
39             $node->setNode('body', new Twig_Node_Body(array(
40                 new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName),
41                 $node->getNode('body'),
42                 new Twig_Profiler_Node_LeaveProfile($varName),
43             )));
44         } elseif ($node instanceof Twig_Node_Macro) {
45             $varName = $this->getVarName();
46             $node->setNode('body', new Twig_Node_Body(array(
47                 new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName),
48                 $node->getNode('body'),
49                 new Twig_Profiler_Node_LeaveProfile($varName),
50             )));
51         }
52
53         return $node;
54     }
55
56     private function getVarName()
57     {
58         return sprintf('__internal_%s', hash('sha256', $this->extensionName));
59     }
60
61     public function getPriority()
62     {
63         return 0;
64     }
65 }
66
67 class_alias('Twig_Profiler_NodeVisitor_Profiler', 'Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', false);