fork download
  1. <?php
  2. class Logger {
  3. public function debug($input) {
  4. var_dump($input);
  5. }
  6. public function log($input) {
  7. echo $input;
  8. }
  9. }
  10.  
  11. class Debug {
  12. protected $logger;
  13. protected static $_instance = NULL;
  14.  
  15. final private function __construct() {
  16. $this->logger = new Logger();
  17. }
  18.  
  19. final private function __clone() { }
  20.  
  21. final public static function getInstance()
  22. {
  23. if(null !== static::$_instance){
  24. return static::$_instance;
  25. }
  26. static::$_instance = new static();
  27.  
  28. return static::$_instance;
  29. }
  30.  
  31. public function getLogger()
  32. {
  33. return $this->logger;
  34. }
  35.  
  36. static public function __callStatic($name, $args)
  37. {
  38. $logger = self::getInstance()->getLogger();
  39. if(method_exists($logger, $name)) {
  40.  
  41. return $logger->{$name}(...$args);
  42. }
  43. }
  44. }
  45.  
  46. function debug($input)
  47. {
  48. Debug::debug($input);
  49. }
  50.  
  51. function traceLog($input)
  52. {
  53. Debug::log($input);
  54. }
  55.  
  56.  
  57. debug(['42','asdfasdf',33]);
  58.  
  59. traceLog("Moving to track 3");
  60.  
Success #stdin #stdout 0.02s 24356KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(2) "42"
  [1]=>
  string(8) "asdfasdf"
  [2]=>
  int(33)
}
Moving to track 3