ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
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'),
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'),
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
67class_alias('Twig_Profiler_NodeVisitor_Profiler', 'Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', false);
sprintf('%.4f', $callTime)
$env
An exception for terminatinating execution or to throw for unit testing.
Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2....
Stores the Twig configuration.
Definition: Environment.php:18
Represents a block node.
Definition: Block.php:19
Represents a body node.
Definition: Body.php:18
Represents a macro node.
Definition: Macro.php:18
Represents a module node.
Definition: Module.php:23
Represents a node in the AST.
Definition: Node.php:19
setNode($name, $node=null)
Definition: Node.php:195
getAttribute($name)
Definition: Node.php:152
getTemplateName()
Definition: Node.php:229
getNode($name)
Definition: Node.php:186
doLeaveNode(Twig_Node $node, Twig_Environment $env)
Called after child nodes are visited.
Definition: Profiler.php:31
getPriority()
Returns the priority for this visitor.
Definition: Profiler.php:61
doEnterNode(Twig_Node $node, Twig_Environment $env)
Called before child nodes are visited.
Definition: Profiler.php:26
Represents a profile enter node.
Represents a profile leave node.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406