2023-12-28 17:32:27 +04:00
|
|
|
<?php
|
|
|
|
namespace nulib\output;
|
|
|
|
|
|
|
|
use nulib\ValueException;
|
|
|
|
use nulib\output\std\ProxyMessenger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class log: inscrire un message dans les logs uniquement
|
2024-04-25 17:46:18 +04:00
|
|
|
*
|
|
|
|
* Cette classe (ou la classe parallèle {@link msg} DOIT être initialisée avant
|
|
|
|
* d'être utilisée
|
2023-12-28 17:32:27 +04:00
|
|
|
*/
|
|
|
|
class log extends _messenger {
|
|
|
|
static function set_messenger(IMessenger $log=null) {
|
|
|
|
self::$log = $log;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function set_messenger_class(string $log_class=null, ?array $params=null) {
|
|
|
|
if (!is_subclass_of($log_class, IMessenger::class)) {
|
|
|
|
throw ValueException::invalid_class($log_class, IMessenger::class);
|
|
|
|
}
|
|
|
|
self::$log = new $log_class($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function get(): IMessenger {
|
|
|
|
if (self::$msg === null) {
|
|
|
|
$msg = self::$log;
|
|
|
|
if ($msg === null) $msg = new ProxyMessenger();
|
|
|
|
self::$msg = $msg;
|
|
|
|
}
|
|
|
|
return self::$msg;
|
|
|
|
}
|
|
|
|
}
|