| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Org_Heigl\AuthLdap; |
| 6 |
|
| 7 |
final class Logger implements LoggerInterface |
| 8 |
{ |
| 9 |
private $debug; |
| 10 |
|
| 11 |
/** |
| 12 |
* @var false|resource |
| 13 |
*/ |
| 14 |
private $fh = false; |
| 15 |
|
| 16 |
public function __construct(bool $debug = false) |
| 17 |
{ |
| 18 |
$this->debug = $debug; |
| 19 |
// $this->fh = fopen('php://stderr', 'w'); |
| 20 |
} |
| 21 |
public function log(string $message): void |
| 22 |
{ |
| 23 |
if (! $this->debug) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
if ($this->fh !== false) { |
| 28 |
fwrite($this->fh, '[AuthLDAP] ' . $message . PHP_EOL); |
| 29 |
} |
| 30 |
error_log('[AuthLDAP] ' . $message, 0); |
| 31 |
} |
| 32 |
|
| 33 |
public function __destruct() |
| 34 |
{ |
| 35 |
if ($this->fh === false) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
fclose($this->fh); |
| 40 |
} |
| 41 |
} |
| 42 |
|