modifs.mineures sans commentaires
This commit is contained in:
parent
7e7069e23f
commit
eb167d431c
|
@ -20,7 +20,9 @@ use nur\sery\output\std\StdMessenger as nStdMessenger;
|
||||||
abstract class Application {
|
abstract class Application {
|
||||||
protected static function _app_init(): void {
|
protected static function _app_init(): void {
|
||||||
config::set_fact(config::FACT_CLI_APP);
|
config::set_fact(config::FACT_CLI_APP);
|
||||||
|
|
||||||
nmsg::set_messenger_class(nStdMessenger::class);
|
nmsg::set_messenger_class(nStdMessenger::class);
|
||||||
|
nmsg::reset_params(["min_level" => nmsg::DEBUG]);
|
||||||
|
|
||||||
msg::set_messenger_class(Console::class);
|
msg::set_messenger_class(Console::class);
|
||||||
msg::get()->setParametrableParams([
|
msg::get()->setParametrableParams([
|
||||||
|
@ -52,6 +54,7 @@ abstract class Application {
|
||||||
# revenir à la configuration par défaut une fois que la configuration
|
# revenir à la configuration par défaut une fois que la configuration
|
||||||
# initiale est faite
|
# initiale est faite
|
||||||
msg::get()->setLevels(msg::PRINT_LEVELS, msg::LOG_LEVELS, msg::TYPE_LEVELS);
|
msg::get()->setLevels(msg::PRINT_LEVELS, msg::LOG_LEVELS, msg::TYPE_LEVELS);
|
||||||
|
nsay::reset_params(["min_level" => nmsg::NORMAL]);
|
||||||
|
|
||||||
$app->parseArgs();
|
$app->parseArgs();
|
||||||
config::configure();
|
config::configure();
|
||||||
|
@ -232,6 +235,7 @@ abstract class Application {
|
||||||
"output" => $logfile,
|
"output" => $logfile,
|
||||||
], nStdMessenger::class, [
|
], nStdMessenger::class, [
|
||||||
"add_date" => true,
|
"add_date" => true,
|
||||||
|
"min_level" => nlog::MINOR,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
static function set_application_color(bool $color): void {
|
static function set_application_color(bool $color): void {
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace nur\sery\output;
|
||||||
* Interface IMessenger: un objet pouvant afficher des messages de l'application
|
* Interface IMessenger: un objet pouvant afficher des messages de l'application
|
||||||
*/
|
*/
|
||||||
interface IMessenger {
|
interface IMessenger {
|
||||||
const DEBUG = -1, MINOR = 0, NORMAL = 1, MAJOR = 2, NONE = 3;
|
const DEBUG = 0, MINOR = 1, NORMAL = 2, MAJOR = 3, NONE = 4;
|
||||||
const MIN_LEVEL = self::DEBUG, MAX_LEVEL = self::MAJOR;
|
const MIN_LEVEL = self::DEBUG, MAX_LEVEL = self::MAJOR;
|
||||||
|
|
||||||
/** réinitialiser les paramètres de l'objet */
|
/** réinitialiser les paramètres de l'objet */
|
||||||
|
|
|
@ -50,11 +50,11 @@ class ProxyMessenger implements IMessenger {
|
||||||
$useFunc = false;
|
$useFunc = false;
|
||||||
$untils = [];
|
$untils = [];
|
||||||
foreach ($this->msgs as $msg) {
|
foreach ($this->msgs as $msg) {
|
||||||
$msg->title($content, null, $level);
|
|
||||||
if ($msg instanceof _IMessenger) {
|
if ($msg instanceof _IMessenger) {
|
||||||
$useFunc = true;
|
$useFunc = true;
|
||||||
$untils[] = $msg->_getTitleMark();
|
$untils[] = $msg->_getTitleMark();
|
||||||
}
|
}
|
||||||
|
$msg->title($content, null, $level);
|
||||||
}
|
}
|
||||||
if ($useFunc && $func !== null) {
|
if ($useFunc && $func !== null) {
|
||||||
try {
|
try {
|
||||||
|
@ -63,11 +63,13 @@ class ProxyMessenger implements IMessenger {
|
||||||
/** @var _IMessenger $msg */
|
/** @var _IMessenger $msg */
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($this->msgs as $msg) {
|
foreach ($this->msgs as $msg) {
|
||||||
|
if ($msg instanceof _IMessenger) {
|
||||||
$msg->_endTitle($untils[$index++]);
|
$msg->_endTitle($untils[$index++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function desc($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->desc($content, $level); } }
|
function desc($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->desc($content, $level); } }
|
||||||
function action($content, ?callable $func=null, ?int $level=null): void {
|
function action($content, ?callable $func=null, ?int $level=null): void {
|
||||||
$useFunc = false;
|
$useFunc = false;
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
require(__DIR__.'/../vendor/autoload.php');
|
||||||
|
|
||||||
|
use nur\cli\Application;
|
||||||
|
use nur\sery\output\IMessenger;
|
||||||
|
use nur\sery\output\msg;
|
||||||
|
use nur\sery\ValueException;
|
||||||
|
|
||||||
|
Application::run(new class extends Application {
|
||||||
|
function main() {
|
||||||
|
msg::title("major", function (IMessenger $msg) {
|
||||||
|
$msg->error("error", msg::MAJOR);
|
||||||
|
$msg->warn("warn", msg::MAJOR);
|
||||||
|
$msg->note("note", msg::MAJOR);
|
||||||
|
$msg->info("info", msg::MAJOR);
|
||||||
|
$msg->info(new ValueException("exception"), msg::MAJOR);
|
||||||
|
}, msg::MAJOR);
|
||||||
|
msg::title("normal", function (IMessenger $msg) {
|
||||||
|
$msg->error("error", msg::NORMAL);
|
||||||
|
$msg->warn("warn", msg::NORMAL);
|
||||||
|
$msg->note("note", msg::NORMAL);
|
||||||
|
$msg->info("info", msg::NORMAL);
|
||||||
|
$msg->info(new ValueException("exception"), msg::NORMAL);
|
||||||
|
}, msg::NORMAL);
|
||||||
|
msg::title("minor", function (IMessenger $msg) {
|
||||||
|
$msg->error("error", msg::MINOR);
|
||||||
|
$msg->warn("warn", msg::MINOR);
|
||||||
|
$msg->note("note", msg::MINOR);
|
||||||
|
$msg->info("info", msg::MINOR);
|
||||||
|
$msg->info(new ValueException("exception"), msg::MINOR);
|
||||||
|
}, msg::MINOR);
|
||||||
|
msg::title("debug", function (IMessenger $msg) {
|
||||||
|
$msg->error("error", msg::DEBUG);
|
||||||
|
$msg->warn("warn", msg::DEBUG);
|
||||||
|
$msg->note("note", msg::DEBUG);
|
||||||
|
$msg->info("info", msg::DEBUG);
|
||||||
|
$msg->info(new ValueException("exception"), msg::DEBUG);
|
||||||
|
}, msg::DEBUG);
|
||||||
|
}
|
||||||
|
});
|
|
@ -2,8 +2,8 @@
|
||||||
<?php
|
<?php
|
||||||
require(__DIR__.'/../vendor/autoload.php');
|
require(__DIR__.'/../vendor/autoload.php');
|
||||||
|
|
||||||
use nulib\UserException;
|
|
||||||
use nur\sery\output\std\StdMessenger;
|
use nur\sery\output\std\StdMessenger;
|
||||||
|
use nur\sery\UserException;
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$count = count($argv) - 1;
|
$count = count($argv) - 1;
|
||||||
|
|
Loading…
Reference in New Issue