StopwatchNode.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Twig\Node;
  11. use Twig\Compiler;
  12. use Twig\Node\Expression\AssignNameExpression;
  13. use Twig\Node\Node;
  14. /**
  15. * Represents a stopwatch node.
  16. *
  17. * @author Wouter J <wouter@wouterj.nl>
  18. */
  19. final class StopwatchNode extends Node
  20. {
  21. public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, string $tag = null)
  22. {
  23. parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
  24. }
  25. public function compile(Compiler $compiler): void
  26. {
  27. $compiler
  28. ->addDebugInfo($this)
  29. ->write('')
  30. ->subcompile($this->getNode('var'))
  31. ->raw(' = ')
  32. ->subcompile($this->getNode('name'))
  33. ->write(";\n")
  34. ->write("\$this->env->getExtension('Symfony\Bridge\Twig\Extension\StopwatchExtension')->getStopwatch()->start(")
  35. ->subcompile($this->getNode('var'))
  36. ->raw(", 'template');\n")
  37. ->subcompile($this->getNode('body'))
  38. ->write("\$this->env->getExtension('Symfony\Bridge\Twig\Extension\StopwatchExtension')->getStopwatch()->stop(")
  39. ->subcompile($this->getNode('var'))
  40. ->raw(");\n")
  41. ;
  42. }
  43. }