You are here

class Twig_Profiler_NodeVisitor_Profiler in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php \Twig_Profiler_NodeVisitor_Profiler

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of Twig_Profiler_NodeVisitor_Profiler

File

vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php, line 15

View source
class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor {
  private $extensionName;
  public function __construct($extensionName) {
    $this->extensionName = $extensionName;
  }

  /**
   * {@inheritdoc}
   */
  protected function doEnterNode(Twig_Node $node, Twig_Environment $env) {
    return $node;
  }

  /**
   * {@inheritdoc}
   */
  protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) {
    if ($node instanceof Twig_Node_Module) {
      $varName = $this
        ->getVarName();
      $node
        ->setNode('display_start', new Twig_Node(array(
        new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node
          ->getAttribute('filename'), $varName),
        $node
          ->getNode('display_start'),
      )));
      $node
        ->setNode('display_end', new Twig_Node(array(
        new Twig_Profiler_Node_LeaveProfile($varName),
        $node
          ->getNode('display_end'),
      )));
    }
    elseif ($node instanceof Twig_Node_Block) {
      $varName = $this
        ->getVarName();
      $node
        ->setNode('body', new Twig_Node_Body(array(
        new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node
          ->getAttribute('name'), $varName),
        $node
          ->getNode('body'),
        new Twig_Profiler_Node_LeaveProfile($varName),
      )));
    }
    elseif ($node instanceof Twig_Node_Macro) {
      $varName = $this
        ->getVarName();
      $node
        ->setNode('body', new Twig_Node_Body(array(
        new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node
          ->getAttribute('name'), $varName),
        $node
          ->getNode('body'),
        new Twig_Profiler_Node_LeaveProfile($varName),
      )));
    }
    return $node;
  }
  private function getVarName() {
    return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
  }

  /**
   * {@inheritdoc}
   */
  public function getPriority() {
    return 0;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Twig_BaseNodeVisitor::enterNode final public function Called before child nodes are visited. Overrides Twig_NodeVisitorInterface::enterNode
Twig_BaseNodeVisitor::leaveNode final public function Called after child nodes are visited. Overrides Twig_NodeVisitorInterface::leaveNode
Twig_Profiler_NodeVisitor_Profiler::$extensionName private property
Twig_Profiler_NodeVisitor_Profiler::doEnterNode protected function Called before child nodes are visited. Overrides Twig_BaseNodeVisitor::doEnterNode
Twig_Profiler_NodeVisitor_Profiler::doLeaveNode protected function Called after child nodes are visited. Overrides Twig_BaseNodeVisitor::doLeaveNode
Twig_Profiler_NodeVisitor_Profiler::getPriority public function Returns the priority for this visitor. Overrides Twig_NodeVisitorInterface::getPriority
Twig_Profiler_NodeVisitor_Profiler::getVarName private function
Twig_Profiler_NodeVisitor_Profiler::__construct public function