ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Profiler.php
Go to the documentation of this file.
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 
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);
getTemplateName()
Definition: Node.php:229
Represents a node in the AST.
Definition: Node.php:18
doEnterNode(Twig_Node $node, Twig_Environment $env)
Definition: Profiler.php:26
getPriority()
Returns the priority for this visitor.
Definition: Profiler.php:61
Represents a macro node.
Definition: Macro.php:17
Represents a block node.
Definition: Block.php:18
setNode($name, $node=null)
Definition: Node.php:195
$env
doLeaveNode(Twig_Node $node, Twig_Environment $env)
Definition: Profiler.php:31
Represents a profile leave node.
Represents a body node.
Definition: Body.php:17
Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2...
getAttribute($name)
Definition: Node.php:152
Represents a module node.
Definition: Module.php:22
Represents a profile enter node.
getNode($name)
Definition: Node.php:186
Stores the Twig configuration.
Definition: Environment.php:17
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406