Profiler.php 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2015 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Extension_Profiler extends Twig_Extension
  11. {
  12. private $actives = array();
  13. public function __construct(Twig_Profiler_Profile $profile)
  14. {
  15. $this->actives[] = $profile;
  16. }
  17. public function enter(Twig_Profiler_Profile $profile)
  18. {
  19. $this->actives[0]->addProfile($profile);
  20. array_unshift($this->actives, $profile);
  21. }
  22. public function leave(Twig_Profiler_Profile $profile)
  23. {
  24. $profile->leave();
  25. array_shift($this->actives);
  26. if (1 === count($this->actives)) {
  27. $this->actives[0]->leave();
  28. }
  29. }
  30. public function getNodeVisitors()
  31. {
  32. return array(new Twig_Profiler_NodeVisitor_Profiler($this->getName()));
  33. }
  34. public function getName()
  35. {
  36. return 'profiler';
  37. }
  38. }