[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/twig/twig/src/Profiler/NodeVisitor/ -> ProfilerNodeVisitor.php (source)

   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  namespace Twig\Profiler\NodeVisitor;
  13  
  14  use Twig\Environment;
  15  use Twig\Node\BlockNode;
  16  use Twig\Node\BodyNode;
  17  use Twig\Node\MacroNode;
  18  use Twig\Node\ModuleNode;
  19  use Twig\Node\Node;
  20  use Twig\NodeVisitor\AbstractNodeVisitor;
  21  use Twig\Profiler\Node\EnterProfileNode;
  22  use Twig\Profiler\Node\LeaveProfileNode;
  23  use Twig\Profiler\Profile;
  24  
  25  /**
  26   * @author Fabien Potencier <fabien@symfony.com>
  27   *
  28   * @final
  29   */
  30  class ProfilerNodeVisitor extends AbstractNodeVisitor
  31  {
  32      private $extensionName;
  33  
  34      public function __construct($extensionName)
  35      {
  36          $this->extensionName = $extensionName;
  37      }
  38  
  39      protected function doEnterNode(Node $node, Environment $env)
  40      {
  41          return $node;
  42      }
  43  
  44      protected function doLeaveNode(Node $node, Environment $env)
  45      {
  46          if ($node instanceof ModuleNode) {
  47              $varName = $this->getVarName();
  48              $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')]));
  49              $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')]));
  50          } elseif ($node instanceof BlockNode) {
  51              $varName = $this->getVarName();
  52              $node->setNode('body', new BodyNode([
  53                  new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName),
  54                  $node->getNode('body'),
  55                  new LeaveProfileNode($varName),
  56              ]));
  57          } elseif ($node instanceof MacroNode) {
  58              $varName = $this->getVarName();
  59              $node->setNode('body', new BodyNode([
  60                  new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName),
  61                  $node->getNode('body'),
  62                  new LeaveProfileNode($varName),
  63              ]));
  64          }
  65  
  66          return $node;
  67      }
  68  
  69      private function getVarName()
  70      {
  71          return sprintf('__internal_%s', hash('sha256', $this->extensionName));
  72      }
  73  
  74      public function getPriority()
  75      {
  76          return 0;
  77      }
  78  }
  79  
  80  class_alias('Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', 'Twig_Profiler_NodeVisitor_Profiler');


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1