80 lines
3.4 KiB
PHP
80 lines
3.4 KiB
PHP
|
<?php
|
||
|
namespace nulib\output;
|
||
|
|
||
|
use nulib\str;
|
||
|
use nulib\ValueException;
|
||
|
|
||
|
/**
|
||
|
* Class _messenger: classe de base pour say, log et msg
|
||
|
*/
|
||
|
abstract class _messenger {
|
||
|
/** @var IMessenger */
|
||
|
protected static $say;
|
||
|
|
||
|
/** @var IMessenger */
|
||
|
protected static $log;
|
||
|
|
||
|
abstract static function get(): IMessenger;
|
||
|
|
||
|
/** obtenir une nouvelle instance, avec un nouveau paramétrage */
|
||
|
static function new(?array $params=null): IMessenger {
|
||
|
return static::get()->clone($params);
|
||
|
}
|
||
|
|
||
|
/** @var IMessenger */
|
||
|
protected static $msg;
|
||
|
|
||
|
/** @var IMessenger[] */
|
||
|
protected static $stack;
|
||
|
|
||
|
/** pousser une nouvelle instance avec un nouveau paramétrage sur la pile */
|
||
|
static function push(?array $params=null) {
|
||
|
self::$stack[] = static::get();
|
||
|
self::$msg = self::new($params);
|
||
|
}
|
||
|
|
||
|
/** dépiler la précédente instance */
|
||
|
static function pop(): IMessenger {
|
||
|
if (self::$stack) $msg = self::$msg = array_pop(self::$stack);
|
||
|
else $msg = self::$msg;
|
||
|
return $msg;
|
||
|
}
|
||
|
|
||
|
static final function __callStatic($name, $args) {
|
||
|
$name = str::us2camel($name);
|
||
|
call_user_func_array([static::get(), $name], $args);
|
||
|
}
|
||
|
|
||
|
#############################################################################
|
||
|
|
||
|
const DEBUG = IMessenger::DEBUG;
|
||
|
const MINOR = IMessenger::MINOR;
|
||
|
const NORMAL = IMessenger::NORMAL;
|
||
|
const MAJOR = IMessenger::MAJOR;
|
||
|
const NONE = IMessenger::NONE;
|
||
|
|
||
|
static function reset_params(?array $params=null): void { static::get()->resetParams($params); }
|
||
|
static function section($content, ?callable $func=null, ?int $level=null): void { static::get()->section($content, $func, $level); }
|
||
|
static function title($content, ?callable $func=null, ?int $level=null): void { static::get()->title($content, $func, $level); }
|
||
|
static function desc($content, ?int $level=null): void { static::get()->desc($content, $level); }
|
||
|
static function action($content, ?callable $func=null, ?int $level=null): void { static::get()->action($content, $func, $level); }
|
||
|
static function step($content, ?int $level=null): void { static::get()->step($content, $level); }
|
||
|
static function asuccess($content=null): void { static::get()->asuccess($content); }
|
||
|
static function afailure($content=null): void { static::get()->afailure($content); }
|
||
|
static function adone($content=null): void { static::get()->adone($content); }
|
||
|
static function print($content, ?int $level=null): void { static::get()->print($content, $level); }
|
||
|
static function info($content, ?int $level=null): void { static::get()->info($content, $level); }
|
||
|
static function note($content, ?int $level=null): void { static::get()->note($content, $level); }
|
||
|
static function warn($content, ?int $level=null): void { static::get()->warn($content, $level); }
|
||
|
static function error($content, ?int $level=null): void { static::get()->error($content, $level); }
|
||
|
static function end(bool $all=false): void { static::get()->end($all); }
|
||
|
|
||
|
static function debug($content): void { self::info($content, self::DEBUG);}
|
||
|
static function normal($content): void { self::info($content, self::NORMAL);}
|
||
|
static function minor($content): void { self::info($content, self::MINOR);}
|
||
|
static function important($content): void { self::info($content, self::MAJOR);}
|
||
|
static function attention($content): void { self::note($content, self::MAJOR);}
|
||
|
static function critwarn($content): void { self::warn($content, self::MAJOR);}
|
||
|
static function criterror($content): void { self::error($content, self::MAJOR);}
|
||
|
}
|