DebugAutoLog.class.php 915 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Debug auto logging class (destructor-based)
  4. *
  5. * @author Yuriy Nasretdinov <nasretdinov@gmail.com>
  6. * @copyright Copyright (c) 2013 Christopher Han
  7. * @package GitPHP
  8. */
  9. class GitPHP_DebugAutoLog
  10. {
  11. private $name;
  12. public function __construct($name = null)
  13. {
  14. if (is_null($name)) {
  15. if (PHP_VERSION_ID >= 50306)
  16. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  17. else
  18. $trace = debug_backtrace();
  19. if (!isset($trace[1]['class']) || !isset($trace[1]['function'])) {
  20. throw new InvalidArgumentException("You need to specify name when not in method context");
  21. }
  22. $name = $trace[1]['class'] . '::' . $trace[1]['function'];
  23. }
  24. $this->name = $name;
  25. GitPHP_DebugLog::GetInstance()->TimerStart();
  26. }
  27. public function __destruct()
  28. {
  29. GitPHP_DebugLog::GetInstance()->TimerStop($this->name);
  30. }
  31. }