TimedPhpEngine.php 1.3 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\Bundle\FrameworkBundle\Templating;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Symfony\Component\Stopwatch\Stopwatch;
  13. use Symfony\Component\Templating\Loader\LoaderInterface;
  14. use Symfony\Component\Templating\TemplateNameParserInterface;
  15. /**
  16. * Times the time spent to render a template.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class TimedPhpEngine extends PhpEngine
  21. {
  22. protected $stopwatch;
  23. public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, Stopwatch $stopwatch, GlobalVariables $globals = null)
  24. {
  25. parent::__construct($parser, $container, $loader, $globals);
  26. $this->stopwatch = $stopwatch;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function render($name, array $parameters = array())
  32. {
  33. $e = $this->stopwatch->start(sprintf('template.php (%s)', $name), 'template');
  34. $ret = parent::render($name, $parameters);
  35. $e->stop();
  36. return $ret;
  37. }
  38. }