68 lines
3.2 KiB
PHP
68 lines
3.2 KiB
PHP
|
<?php
|
||
|
namespace nur\sery\output;
|
||
|
|
||
|
use nulib\ValueException;
|
||
|
use nulib\str;
|
||
|
|
||
|
/**
|
||
|
* Class _messenger: classe de base pour say, log et msg
|
||
|
*/
|
||
|
abstract class _messenger {
|
||
|
/** @var IMessenger */
|
||
|
protected static $say;
|
||
|
|
||
|
/** @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::unexpected_class($say_class, IMessenger::class);
|
||
|
}
|
||
|
self::$say = new $say_class();
|
||
|
if ($log_class !== null) {
|
||
|
if (!is_subclass_of($log_class, IMessenger::class)) {
|
||
|
throw ValueException::unexpected_class($log_class, IMessenger::class);
|
||
|
}
|
||
|
self::$log = new $log_class();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** @return IMessenger[] */
|
||
|
abstract static function get_msgs(): array;
|
||
|
|
||
|
static final function __callStatic($name, $args) {
|
||
|
$name = str::us2camel($name);
|
||
|
foreach (static::get_msgs() as $msg) {
|
||
|
call_user_func_array([$msg, $name], $args);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#############################################################################
|
||
|
|
||
|
const DEBUG = IMessenger::LEVEL_DEBUG;
|
||
|
const NORMAL = IMessenger::LEVEL_NORMAL;
|
||
|
const MAJOR = IMessenger::LEVEL_MAJOR;
|
||
|
const NONE = IMessenger::LEVEL_NONE;
|
||
|
|
||
|
static function reset_params(?array $params) { foreach (static::get_msgs() as $msg) { $msg->resetParams($params); } }
|
||
|
function section($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->section($content, $level); } }
|
||
|
function title($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->title($content, $level); } }
|
||
|
function desc($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->desc($content, $level); } }
|
||
|
function action($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->action($content, $level); } }
|
||
|
function step($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->step($content, $level); } }
|
||
|
function asuccess($content=null): void { foreach (static::get_msgs() as $msg) { $msg->asuccess($content); } }
|
||
|
function afailure($content=null): void { foreach (static::get_msgs() as $msg) { $msg->afailure($content); } }
|
||
|
function adone($content=null): void { foreach (static::get_msgs() as $msg) { $msg->adone($content); } }
|
||
|
function print($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->print($content, $level); } }
|
||
|
function info($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->info($content, $level); } }
|
||
|
function note($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->note($content, $level); } }
|
||
|
function warn($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->warn($content, $level); } }
|
||
|
function error($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->error($content, $level); } }
|
||
|
function end(bool $all=false): void { foreach (static::get_msgs() as $msg) { $msg->end($all); } }
|
||
|
}
|