nulib/php/src_output/say.php

31 lines
746 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
*/
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;
}
}