Created
March 26, 2020 09:04
-
-
Save Kcko/3473b0ba26949d1cdea3932a43e400a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DebuggerEcho implements Debugger | |
{ | |
protected function __construct() {} | |
private function __clone() {} | |
public static function getInstance() | |
{ | |
if (null == self::$instance) | |
{ | |
self::$instance = new self(); | |
} | |
return self::$instance; | |
} | |
public function debug($message) | |
{ | |
print $message . "\n"; | |
} | |
} | |
// AKA multition | |
class DebuggerLog implements Debugger | |
{ | |
protected $logfile = null; | |
private static $instances = array(); | |
public static function getInstance($logfile) | |
{ | |
if (!isset(self::$instances[$logfile])) { | |
self::$instances[$logfile] = new self($logfile); | |
} | |
return self::$instances[$logfile]; | |
} | |
protected function __construct($logfile) | |
{ | |
$this->logfile = $logfile; | |
} | |
private function __clone() | |
{ | |
} | |
public function debug($message) | |
{ | |
error_log($message . "\n", 3, $this->logfile); | |
} | |
} | |
// usage | |
$debugger1 = DebuggerLog::getInstance('./debugger1.log'); | |
$debugger1->debug('Lorem ipsum dolor sit amet.'); | |
$debugger2 = DebuggerLog::getInstance('./debugger2.log'); | |
$debugger2->debug('Proin fringilla bibendum sagittis.'); | |
$debugger3 = DebuggerLog::getInstance('./debugger1.log'); | |
$debugger3->debug('Mauris vitae augue dolor.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment