nur-sery/nur_src/v/al.php

62 lines
2.6 KiB
PHP

<?php
namespace nur\v;
use nur\str;
use nur\v\base\Alerter;
/**
* Class al: gestion globale des alertes
*/
class al {
static final function new(?Alerter &$alerter=null, ?array $params=null): Alerter {
if ($alerter === null) $alerter = new Alerter($params);
return $alerter;
}
/** @var Alerter */
private static $alerter;
static final function get(): Alerter {
return self::new(self::$alerter, [
"auto_session" => true,
]);
}
static final function __callStatic($name, $args) {
$name = str::us2camel($name);
return call_user_func_array([self::get(), $name], $args);
}
#############################################################################
# Types de messages
const ERROR = Alerter::TYPE_ERROR;
const WARNING = Alerter::TYPE_WARNING;
const FAILURE = Alerter::TYPE_FAILURE;
const SUCCESS = Alerter::TYPE_SUCCESS;
const NOTE = Alerter::TYPE_NOTE;
const INFO = Alerter::TYPE_INFO;
const DEBUG = Alerter::TYPE_DEBUG;
static final function reset(?bool $autoSession=null): void { self::get()->reset($autoSession); }
static final function set_redirect($redirect=false, ?bool $dismissible=null): Alerter { return self::get()->setRedirect($redirect, $dismissible); }
static final function add($message, int $type): Alerter { $al = self::get(); $al->add($message, $type); return $al; }
static final function print(): void { self::get()->print(); }
static final function error($message): Alerter { return self::get()->error($message); }
static final function warning($message): Alerter { return self::get()->warning($message); }
static final function note($message): Alerter { return self::get()->note($message); }
static final function success($message): Alerter { return self::get()->success($message); }
static final function failure($message): Alerter { return self::get()->failure($message); }
static final function info($message): Alerter { return self::get()->info($message); }
static final function debug($message): Alerter { return self::get()->debug($message); }
static final function perror($message): void { self::get()->perror($message); }
static final function pwarning($message): void { self::get()->pwarning($message); }
static final function pnote($message): void { self::get()->pnote($message); }
static final function psuccess($message): void { self::get()->psuccess($message); }
static final function pfailure($message): void { self::get()->pfailure($message); }
static final function pinfo($message): void { self::get()->pinfo($message); }
static final function pdebug($message): void { self::get()->pdebug($message); }
}