modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-05-03 08:07:18 +04:00
parent 7e7069e23f
commit eb167d431c
5 changed files with 51 additions and 4 deletions

View File

@ -20,7 +20,9 @@ use nur\sery\output\std\StdMessenger as nStdMessenger;
abstract class Application {
protected static function _app_init(): void {
config::set_fact(config::FACT_CLI_APP);
nmsg::set_messenger_class(nStdMessenger::class);
nmsg::reset_params(["min_level" => nmsg::DEBUG]);
msg::set_messenger_class(Console::class);
msg::get()->setParametrableParams([
@ -52,6 +54,7 @@ abstract class Application {
# revenir à la configuration par défaut une fois que la configuration
# initiale est faite
msg::get()->setLevels(msg::PRINT_LEVELS, msg::LOG_LEVELS, msg::TYPE_LEVELS);
nsay::reset_params(["min_level" => nmsg::NORMAL]);
$app->parseArgs();
config::configure();
@ -232,6 +235,7 @@ abstract class Application {
"output" => $logfile,
], nStdMessenger::class, [
"add_date" => true,
"min_level" => nlog::MINOR,
]);
}
static function set_application_color(bool $color): void {

View File

@ -5,7 +5,7 @@ namespace nur\sery\output;
* Interface IMessenger: un objet pouvant afficher des messages de l'application
*/
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;
/** réinitialiser les paramètres de l'objet */

View File

@ -50,11 +50,11 @@ class ProxyMessenger implements IMessenger {
$useFunc = false;
$untils = [];
foreach ($this->msgs as $msg) {
$msg->title($content, null, $level);
if ($msg instanceof _IMessenger) {
$useFunc = true;
$untils[] = $msg->_getTitleMark();
}
$msg->title($content, null, $level);
}
if ($useFunc && $func !== null) {
try {
@ -63,7 +63,9 @@ class ProxyMessenger implements IMessenger {
/** @var _IMessenger $msg */
$index = 0;
foreach ($this->msgs as $msg) {
$msg->_endTitle($untils[$index++]);
if ($msg instanceof _IMessenger) {
$msg->_endTitle($untils[$index++]);
}
}
}
}

41
tbin/legacy-test-levels.php Executable file
View File

@ -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);
}
});

View File

@ -2,8 +2,8 @@
<?php
require(__DIR__.'/../vendor/autoload.php');
use nulib\UserException;
use nur\sery\output\std\StdMessenger;
use nur\sery\UserException;
$params = [];
$count = count($argv) - 1;