nulib/php/src_output/say.php

34 lines
853 B
PHP
Raw Normal View History

2023-12-28 17:32:27 +04:00
<?php
namespace nulib\output;
use nulib\ValueException;
use nulib\output\std\ProxyMessenger;
/**
* Class say: afficher un message sur la console 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 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;
if ($msg === null) $msg = new ProxyMessenger();
self::$msg = $msg;
}
return self::$msg;
}
}