modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2023-12-28 15:59:45 +04:00
parent 1c5674558b
commit 6dd7325fd1
4 changed files with 43 additions and 18 deletions

View File

@ -14,24 +14,6 @@ abstract class _messenger {
/** @var IMessenger */
protected static $log;
static final function set_messenger(IMessenger $say, ?IMessenger $log=null) {
self::$say = $say;
if ($log !== null) self::$log = $log;
}
static final function set_messenger_class(string $say_class, ?string $log_class=null) {
if (!is_subclass_of($say_class, IMessenger::class)) {
throw ValueException::invalid_class($say_class, IMessenger::class);
}
self::$say = new $say_class();
if ($log_class !== null) {
if (!is_subclass_of($log_class, IMessenger::class)) {
throw ValueException::invalid_class($log_class, IMessenger::class);
}
self::$log = new $log_class();
}
}
abstract static function get(): IMessenger;
/** obtenir une nouvelle instance, avec un nouveau paramétrage */

View File

@ -1,12 +1,24 @@
<?php
namespace nur\sery\output;
use nulib\ValueException;
use nur\sery\output\std\ProxyMessenger;
/**
* Class log: inscrire un message dans les logs uniquement
*/
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;

View File

@ -1,12 +1,31 @@
<?php
namespace nur\sery\output;
use nulib\ValueException;
use nur\sery\output\std\ProxyMessenger;
/**
* Class msg: inscrire un message dans les logs ET l'afficher sur la console
*/
class msg extends _messenger {
static function set_messenger(IMessenger $say, ?IMessenger $log=null) {
self::$say = $say;
if ($log !== null) self::$log = $log;
}
static function set_messenger_class(string $say_class, ?string $log_class=null) {
if (!is_subclass_of($say_class, IMessenger::class)) {
throw ValueException::invalid_class($say_class, IMessenger::class);
}
self::$say = new $say_class();
if ($log_class !== null) {
if (!is_subclass_of($log_class, IMessenger::class)) {
throw ValueException::invalid_class($log_class, IMessenger::class);
}
self::$log = new $log_class();
}
}
static function get(): IMessenger {
if (self::$msg === null) {
$log = self::$log;

View File

@ -1,12 +1,24 @@
<?php
namespace nur\sery\output;
use nulib\ValueException;
use nur\sery\output\std\ProxyMessenger;
/**
* Class say: afficher un message sur la console uniquement
*/
class say extends _messenger {
static function set_messenger(IMessenger $say) {
self::$say = $say;
}
static function set_messenger_class(string $say_class, ?array $params=null) {
if (!is_subclass_of($say_class, IMessenger::class)) {
throw ValueException::invalid_class($say_class, IMessenger::class);
}
self::$say = new $say_class($params);
}
static function get(): IMessenger {
if (self::$msg === null) {
$msg = self::$say;