sfTimerManager.class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfTimerManager is a container for sfTimer objects.
  11. *
  12. * @package symfony
  13. * @subpackage util
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfTimerManager.class.php 13339 2008-11-25 14:58:05Z fabien $
  16. */
  17. class sfTimerManager
  18. {
  19. static public $timers = array();
  20. /**
  21. * Gets a sfTimer instance.
  22. *
  23. * It returns the timer named $name or create a new one if it does not exist.
  24. *
  25. * @param string $name The name of the timer
  26. *
  27. * @return sfTimer The timer instance
  28. */
  29. public static function getTimer($name)
  30. {
  31. if (!isset(self::$timers[$name]))
  32. {
  33. self::$timers[$name] = new sfTimer($name);
  34. }
  35. self::$timers[$name]->startTimer();
  36. return self::$timers[$name];
  37. }
  38. /**
  39. * Gets all sfTimer instances stored in sfTimerManager.
  40. *
  41. * @return array An array of all sfTimer instances
  42. */
  43. public static function getTimers()
  44. {
  45. return self::$timers;
  46. }
  47. /**
  48. * Clears all sfTimer instances stored in sfTimerManager.
  49. */
  50. public static function clearTimers()
  51. {
  52. self::$timers = array();
  53. }
  54. }