modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-10-15 15:33:13 +04:00
parent 48d5f84bbd
commit a0c6fb21e6
3 changed files with 85 additions and 97 deletions

View File

@ -84,9 +84,8 @@ abstract class AbstractMessenger implements _IMessenger {
} }
protected function _printTitle( protected function _printTitle(
?string $linePrefix, int $level, int $level, string $type, ?string $linePrefix, int $indentLevel,
string $type, $content, StdOutput $out, $content
int $indentLevel, StdOutput $out
): void { ): void {
$prefixes = self::GENERIC_PREFIXES[$level][$type]; $prefixes = self::GENERIC_PREFIXES[$level][$type];
if ($prefixes[0]) $out->print(); if ($prefixes[0]) $out->print();
@ -136,10 +135,10 @@ abstract class AbstractMessenger implements _IMessenger {
protected abstract function action__flush(bool $endAction=false, ?int $overrideLevel=null): void; protected abstract function action__flush(bool $endAction=false, ?int $overrideLevel=null): void;
protected function _printAction( protected function _printAction(
?string $linePrefix, int $level, int $level, ?string $linePrefix, int $indentLevel,
StdOutput $out,
bool $printContent, $content, bool $printContent, $content,
bool $printResult, ?bool $rsuccess, $rcontent, bool $printResult, ?bool $rsuccess, $rcontent
int $indentLevel, StdOutput $out
): void { ): void {
$color = $out->isColor(); $color = $out->isColor();
if ($rsuccess === true) $type = "success"; if ($rsuccess === true) $type = "success";
@ -211,9 +210,8 @@ abstract class AbstractMessenger implements _IMessenger {
} }
protected function _printGeneric( protected function _printGeneric(
?string $linePrefix, int $level, int $level, string $type, ?string $linePrefix, int $indentLevel,
string $type, $content, StdOutput $out, $content
int $indentLevel, StdOutput $out
): void { ): void {
$prefixes = self::GENERIC_PREFIXES[$level][$type]; $prefixes = self::GENERIC_PREFIXES[$level][$type];
$content = cl::with($content); $content = cl::with($content);
@ -246,9 +244,8 @@ abstract class AbstractMessenger implements _IMessenger {
} }
protected function _printGenericOrException( protected function _printGenericOrException(
?int $level, ?int $level, string $type, int $indentLevel,
string $type, $content, StdOutput $out, $content
int $indentLevel, StdOutput $out
): void { ): void {
$linePrefix = $this->getLinePrefix(); $linePrefix = $this->getLinePrefix();
# si $content contient des exceptions, les afficher avec un level moindre # si $content contient des exceptions, les afficher avec un level moindre
@ -274,7 +271,7 @@ abstract class AbstractMessenger implements _IMessenger {
$showContent = $this->checkLevel($level); $showContent = $this->checkLevel($level);
if ($content !== null && $showContent) { if ($content !== null && $showContent) {
$this->action__flush(); $flushActions = false; $this->action__flush(); $flushActions = false;
$this->_printGeneric($linePrefix, $level, $type, $content, $indentLevel, $out); $this->_printGeneric($level, $type, $linePrefix, $indentLevel, $out, $content);
} }
if ($exceptions !== null) { if ($exceptions !== null) {
$level1 = $this->decrLevel($level); $level1 = $this->decrLevel($level);
@ -284,15 +281,15 @@ abstract class AbstractMessenger implements _IMessenger {
$message = exceptions::get_message($exception); $message = exceptions::get_message($exception);
if ($showContent) { if ($showContent) {
if ($flushActions) { $this->action__flush(); $flushActions = false; } if ($flushActions) { $this->action__flush(); $flushActions = false; }
$this->_printGeneric($linePrefix, $level, $type, $message, $indentLevel, $out); $this->_printGeneric($level, $type, $linePrefix, $indentLevel, $out, $message);
} }
# puis summary et traceback # puis summary et traceback
if ($showTraceback) { if ($showTraceback) {
if ($flushActions) { $this->action__flush(); $flushActions = false; } if ($flushActions) { $this->action__flush(); $flushActions = false; }
$summary = exceptions::get_summary($exception, false); $summary = exceptions::get_summary($exception, false);
$this->_printGeneric($linePrefix, $level1, $type, $summary, $indentLevel, $out); $this->_printGeneric($level1, $type, $linePrefix, $indentLevel, $out, $summary);
$traceback = exceptions::get_traceback($exception); $traceback = exceptions::get_traceback($exception);
$this->_printGeneric($linePrefix, $level1, $type, $traceback, $indentLevel, $out); $this->_printGeneric($level1, $type, $linePrefix, $indentLevel, $out, $traceback);
} }
} }
} }

View File

@ -124,8 +124,8 @@ class ConsoleMessenger extends AbstractMessenger {
$this->inSection = true; $this->inSection = true;
if (!$this->checkLevel($level)) return; if (!$this->checkLevel($level)) return;
$this->section = [ $this->section = [
"msg_level" => $level,
"line_prefix" => $this->getLinePrefix(), "line_prefix" => $this->getLinePrefix(),
"level" => $level,
"content" => $content, "content" => $content,
"print_content" => true, "print_content" => true,
]; ];
@ -142,9 +142,8 @@ class ConsoleMessenger extends AbstractMessenger {
$section =& $this->section; $section =& $this->section;
if ($section !== null && $section["print_content"]) { if ($section !== null && $section["print_content"]) {
$this->_printTitle( $this->_printTitle(
$section["line_prefix"], $section["level"], $section["msg_level"], "section", $section["line_prefix"], 0,
"section", $section["content"], $this->err, $section["content"]);
0, $this->err);
$section["print_content"] = false; $section["print_content"] = false;
} }
} }
@ -154,7 +153,7 @@ class ConsoleMessenger extends AbstractMessenger {
if ($indentLevel < 0) $indentLevel = 0; if ($indentLevel < 0) $indentLevel = 0;
if ($withActions) { if ($withActions) {
foreach ($this->actions as $action) { foreach ($this->actions as $action) {
if ($action["level"] < $this->minLevel) continue; if ($action["msg_level"] < $this->minLevel) continue;
$indentLevel++; $indentLevel++;
} }
} }
@ -189,17 +188,15 @@ class ConsoleMessenger extends AbstractMessenger {
foreach ($this->titles as &$title) { foreach ($this->titles as &$title) {
if ($title["print_content"]) { if ($title["print_content"]) {
$this->_printTitle( $this->_printTitle(
$title["line_prefix"], $title["level"], $title["msg_level"], "title", $title["line_prefix"], $indentLevel,
"title", $title["content"], $err, $title["content"]);
$indentLevel, $err);
$title["print_content"] = false; $title["print_content"] = false;
} }
if ($title["print_descs"]) { if ($title["print_descs"]) {
foreach ($title["descs"] as $desc) { foreach ($title["descs"] as $desc) {
$this->_printGeneric( $this->_printGeneric(
$desc["line_prefix"], $desc["level"], $desc["msg_level"], "desc", $desc["line_prefix"], $indentLevel,
"desc", $desc["content"], $err, $desc["content"]);
$indentLevel, $err);
} }
$title["descs"] = []; $title["descs"] = [];
$title["print_descs"] = false; $title["print_descs"] = false;
@ -227,8 +224,8 @@ class ConsoleMessenger extends AbstractMessenger {
A::merge($this->titles[array_key_last($this->titles)], [ A::merge($this->titles[array_key_last($this->titles)], [
"title_level" => $marks[0], "title_level" => $marks[0],
"max_title_level" => null, "max_title_level" => null,
"msg_level" => $level,
"line_prefix" => $this->getLinePrefix(), "line_prefix" => $this->getLinePrefix(),
"level" => $level,
"content" => $content, "content" => $content,
"print_content" => true, "print_content" => true,
"descs" => [], "descs" => [],
@ -247,8 +244,8 @@ class ConsoleMessenger extends AbstractMessenger {
function desc($content, ?int $level=null): void { function desc($content, ?int $level=null): void {
if (!$this->checkLevel($level)) return; if (!$this->checkLevel($level)) return;
$desc = [ $desc = [
"msg_level" => $level,
"line_prefix" => $this->getLinePrefix(), "line_prefix" => $this->getLinePrefix(),
"level" => $level,
"content" => $content, "content" => $content,
]; ];
$key = array_key_last($this->titles); $key = array_key_last($this->titles);
@ -259,9 +256,8 @@ class ConsoleMessenger extends AbstractMessenger {
} else { } else {
# pas de titre en cours # pas de titre en cours
$this->_printGeneric( $this->_printGeneric(
$desc["line_prefix"], $desc["level"], $desc["msg_level"], "desc", $desc["line_prefix"], 0,
"desc", $desc["content"], $this->err, $desc["content"]);
0, $this->err);
} }
} }
@ -294,8 +290,8 @@ class ConsoleMessenger extends AbstractMessenger {
$index = 0; $index = 0;
foreach ($this->actions as &$action) { foreach ($this->actions as &$action) {
$mergeResult = $index++ == $lastIndex && $endAction; $mergeResult = $index++ == $lastIndex && $endAction;
$level = $overrideLevel?? $action["msg_level"];
$linePrefix = $action["line_prefix"]; $linePrefix = $action["line_prefix"];
$level = $overrideLevel?? $action["level"];
$content = $action["content"]; $content = $action["content"];
$printContent = $action["print_content"]; $printContent = $action["print_content"];
$rsuccess = $action["result_success"]; $rsuccess = $action["result_success"];
@ -304,33 +300,32 @@ class ConsoleMessenger extends AbstractMessenger {
if ($mergeResult) { if ($mergeResult) {
if (time() - $action["timestamp"] <= 2) { if (time() - $action["timestamp"] <= 2) {
$this->_printAction( $this->_printAction(
$linePrefix, $level, $level, $linePrefix, $indentLevel,
$err,
$printContent, $content, $printContent, $content,
true, $rsuccess, $rcontent, true, $rsuccess, $rcontent);
$indentLevel, $err);
} else { } else {
# si l'action a pris plus de 2 secondes, ne pas fusionner pour que # si l'action a pris plus de 2 secondes, ne pas fusionner pour que
# l'on voit le temps que ça a pris # l'on voit le temps que ça a pris
$this->_printAction( $this->_printAction(
$linePrefix, $level, $level, $linePrefix, $indentLevel,
$err,
$printContent, $content, $printContent, $content,
false, null, null, false, null, null);
$indentLevel, $err);
# recalculer une nouvelle ligne de préfixe pour le résultat # recalculer une nouvelle ligne de préfixe pour le résultat
$linePrefix = $this->getLinePrefix(); $linePrefix = $this->getLinePrefix();
$this->_printAction( $this->_printAction(
$linePrefix, $level, $level, $linePrefix, $indentLevel,
$err,
false, null, false, null,
true, $rsuccess, $rcontent, true, $rsuccess, $rcontent);
$indentLevel, $err);
} }
} elseif ($printContent) { } elseif ($printContent) {
$this->_printAction( $this->_printAction(
$linePrefix, $level, $level, $linePrefix, $indentLevel,
$err,
$printContent, $content, $printContent, $content,
false, $rsuccess, $rcontent, false, $rsuccess, $rcontent);
$indentLevel, $err);
$action["print_content"] = false; $action["print_content"] = false;
} }
$indentLevel++; $indentLevel++;
@ -358,8 +353,8 @@ class ConsoleMessenger extends AbstractMessenger {
"action_level" => $marks[0], "action_level" => $marks[0],
"max_action_level" => null, "max_action_level" => null,
"timestamp" => time(), "timestamp" => time(),
"msg_level" => $level,
"line_prefix" => $this->getLinePrefix(), "line_prefix" => $this->getLinePrefix(),
"level" => $level,
"content" => $content, "content" => $content,
"print_content" => true, "print_content" => true,
"result_success" => null, "result_success" => null,
@ -383,8 +378,8 @@ class ConsoleMessenger extends AbstractMessenger {
function step($content, ?int $level=null): void { function step($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "step", $content, $level, "step", $this->getIndentLevel(),
$this->getIndentLevel(), $this->err); $this->err, $content);
} }
function asuccess($content=null, ?int $overrideLevel=null): void { function asuccess($content=null, ?int $overrideLevel=null): void {
@ -421,32 +416,32 @@ class ConsoleMessenger extends AbstractMessenger {
function print($content, ?int $level=null): void { function print($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "print", $content, $level, "print", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function info($content, ?int $level=null): void { function info($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "info", $content, $level, "info", $this->getIndentLevel(),
$this->getIndentLevel(), $this->err); $this->err, $content);
} }
function note($content, ?int $level=null): void { function note($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "note", $content, $level, "note", $this->getIndentLevel(),
$this->getIndentLevel(), $this->err); $this->err, $content);
} }
function warning($content, ?int $level=null): void { function warning($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "warning", $content, $level, "warning", $this->getIndentLevel(),
$this->getIndentLevel(), $this->err); $this->err, $content);
} }
function error($content, ?int $level=null): void { function error($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "error", $content, $level, "error", $this->getIndentLevel(),
$this->getIndentLevel(), $this->err); $this->err, $content);
} }
function end(bool $all=false): void { function end(bool $all=false): void {

View File

@ -91,9 +91,8 @@ class LogMessenger extends AbstractMessenger {
$this->section__end(); $this->section__end();
if (!$this->checkLevel($level)) return; if (!$this->checkLevel($level)) return;
$this->_printTitle( $this->_printTitle(
$this->getLinePrefix(), $level, $level, "section", $this->getLinePrefix(), 0,
"section", $content, $this->out, $content);
0, $this->out);
if ($func !== null) { if ($func !== null) {
try { try {
$func($this); $func($this);
@ -144,9 +143,8 @@ class LogMessenger extends AbstractMessenger {
"max_title_level" => null, "max_title_level" => null,
]; ];
$this->_printTitle( $this->_printTitle(
$this->getLinePrefix(), $level, $level, "title", $this->getLinePrefix(), $marks[0],
"title", $content, $this->out, $content);
$marks[0], $this->out);
if ($func !== null) { if ($func !== null) {
try { try {
$this->title__beforeFunc($marks); $this->title__beforeFunc($marks);
@ -161,10 +159,8 @@ class LogMessenger extends AbstractMessenger {
if (!$this->checkLevel($level)) return; if (!$this->checkLevel($level)) return;
$titleLevel = end($this->titles)["title_level"] ?? 0; $titleLevel = end($this->titles)["title_level"] ?? 0;
$this->_printGeneric( $this->_printGeneric(
$this->getLinePrefix(), $level, $level, "desc", $this->getLinePrefix(), $titleLevel,
"desc", $content, $this->out, $content);
$titleLevel, $this->out);
} }
protected array $actions; protected array $actions;
@ -209,13 +205,13 @@ class LogMessenger extends AbstractMessenger {
"id" => $this->lastActionId++, "id" => $this->lastActionId++,
"action_level" => $marks[0], "action_level" => $marks[0],
"max_action_level" => null, "max_action_level" => null,
"level" => $level "msg_level" => $level
]; ];
$this->_printAction( $this->_printAction(
$this->getLinePrefix(), $level, $level, $this->getLinePrefix(), $marks[0],
$this->out,
true, $content, true, $content,
false, null, null, false, null, null);
$marks[0], $this->out);
if ($func !== null) { if ($func !== null) {
try { try {
$this->action__beforeFunc($marks); $this->action__beforeFunc($marks);
@ -234,43 +230,43 @@ class LogMessenger extends AbstractMessenger {
function step($content, ?int $level=null): void { function step($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "step", $content, $level, "step", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function asuccess($content=null, ?int $overrideLevel=null): void { function asuccess($content=null, ?int $overrideLevel=null): void {
if ($this->action__getMarks()[0] == 0) $this->action(null); if ($this->action__getMarks()[0] == 0) $this->action(null);
$action = end($this->actions); $action = end($this->actions);
$level = $overrideLevel ?? $action["level"]; $level = $overrideLevel ?? $action["msg_level"];
$this->_printAction( $this->_printAction(
$this->getLinePrefix(), $level, $level, $this->getLinePrefix(), $action["action_level"],
$this->out,
false, null, false, null,
true, true, $content, true, true, $content);
$action["action_level"], $this->out);
$this->action__end(); $this->action__end();
} }
function afailure($content=null, ?int $overrideLevel=null): void { function afailure($content=null, ?int $overrideLevel=null): void {
if ($this->action__getMarks()[0] == 0) $this->action(null); if ($this->action__getMarks()[0] == 0) $this->action(null);
$action = end($this->actions); $action = end($this->actions);
$level = $overrideLevel ?? $action["level"]; $level = $overrideLevel ?? $action["msg_level"];
$this->_printAction( $this->_printAction(
$this->getLinePrefix(), $level, $level, $this->getLinePrefix(), $action["action_level"],
$this->out,
false, null, false, null,
true, false, $content, true, false, $content);
$action["action_level"], $this->out);
$this->action__end(); $this->action__end();
} }
function adone($content=null, ?int $overrideLevel=null): void { function adone($content=null, ?int $overrideLevel=null): void {
if ($this->action__getMarks()[0] == 0) $this->action(null); if ($this->action__getMarks()[0] == 0) $this->action(null);
$action = end($this->actions); $action = end($this->actions);
$level = $overrideLevel ?? $action["level"]; $level = $overrideLevel ?? $action["msg_level"];
$this->_printAction( $this->_printAction(
$this->getLinePrefix(), $level, $level, $this->getLinePrefix(), $action["action_level"],
$this->out,
false, null, false, null,
true, null, $content, true, null, $content);
$action["action_level"], $this->out);
$this->action__end(); $this->action__end();
} }
@ -291,32 +287,32 @@ class LogMessenger extends AbstractMessenger {
function print($content, ?int $level=null): void { function print($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "print", $content, $level, "print", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function info($content, ?int $level=null): void { function info($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "info", $content, $level, "info", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function note($content, ?int $level=null): void { function note($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "note", $content, $level, "note", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function warning($content, ?int $level=null): void { function warning($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "warning", $content, $level, "warning", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function error($content, ?int $level=null): void { function error($content, ?int $level=null): void {
$this->_printGenericOrException( $this->_printGenericOrException(
$level, "error", $content, $level, "error", $this->getIndentLevel(),
$this->getIndentLevel(), $this->out); $this->out, $content);
} }
function end(bool $all=false): void { function end(bool $all=false): void {