Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created March 26, 2020 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/3473b0ba26949d1cdea3932a43e400a9 to your computer and use it in GitHub Desktop.
Save Kcko/3473b0ba26949d1cdea3932a43e400a9 to your computer and use it in GitHub Desktop.
<?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