StopwatchHelper.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Helper;
  11. use Symfony\Component\Stopwatch\Stopwatch;
  12. use Symfony\Component\Templating\Helper\Helper;
  13. /**
  14. * StopwatchHelper provides methods time your PHP templates.
  15. *
  16. * @author Wouter J <wouter@wouterj.nl>
  17. */
  18. class StopwatchHelper extends Helper
  19. {
  20. private $stopwatch;
  21. public function __construct(Stopwatch $stopwatch = null)
  22. {
  23. $this->stopwatch = $stopwatch;
  24. }
  25. public function getName()
  26. {
  27. return 'stopwatch';
  28. }
  29. public function __call($method, $arguments = array())
  30. {
  31. if (null !== $this->stopwatch) {
  32. if (method_exists($this->stopwatch, $method)) {
  33. return \call_user_func_array(array($this->stopwatch, $method), $arguments);
  34. }
  35. throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));
  36. }
  37. }
  38. }