nulib/php/src_output/say.php

34 lines
853 B
PHP

<?php
namespace nulib\output;
use nulib\ValueException;
use nulib\output\std\ProxyMessenger;
/**
* Class say: afficher un message sur la console uniquement
*
* Cette classe (ou la classe parallèle {@link msg} DOIT être initialisée avant
* d'être utilisée
*/
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;
}
}