modifs.mineures sans commentaires
This commit is contained in:
parent
a0c6fb21e6
commit
cf5ef38a0f
@ -162,16 +162,21 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
|
||||
protected array $titles;
|
||||
|
||||
protected function title__last(): ?array {
|
||||
$last = end($this->titles);
|
||||
return $last !== false? $last: null;
|
||||
}
|
||||
|
||||
function title__getMarks(): array {
|
||||
return [count($this->titles)];
|
||||
}
|
||||
|
||||
protected function title__getId(): ?int {
|
||||
return end($this->titles)["id"] ?? null;
|
||||
return $this->title__last()["id"] ?? null;
|
||||
}
|
||||
|
||||
protected function title__end(?int $until=null): void {
|
||||
$title = $this->titles[array_key_last($this->titles)] ?? null;
|
||||
$title = $this->title__last();
|
||||
if ($title !== null) {
|
||||
$until ??= $title["max_title_level"];
|
||||
$until ??= $this->title__getMarks()[0] - 1;
|
||||
@ -205,13 +210,17 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
}; unset($title);
|
||||
}
|
||||
|
||||
protected function &title__ref(): ?array {
|
||||
return $this->titles[array_key_last($this->titles)];
|
||||
}
|
||||
|
||||
function title__beforeFunc(array $marks): void {
|
||||
$title =& $this->titles[array_key_last($this->titles)];
|
||||
$title =& $this->title__ref();
|
||||
$title["max_title_level"] = $marks[0] + 1;
|
||||
}
|
||||
|
||||
function title__afterFunc(array $marks): void {
|
||||
$title =& $this->titles[array_key_last($this->titles)];
|
||||
$title =& $this->title__ref();
|
||||
$title["max_title_level"] = null;
|
||||
$this->title__end($marks[0]);
|
||||
}
|
||||
@ -221,7 +230,7 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
$marks = $this->title__getMarks();
|
||||
// faire en deux temps pour linePrefix soit à jour
|
||||
$this->titles[] = ["id" => $this->lastTitleId++];
|
||||
A::merge($this->titles[array_key_last($this->titles)], [
|
||||
A::merge($this->title__ref(), [
|
||||
"title_level" => $marks[0],
|
||||
"max_title_level" => null,
|
||||
"msg_level" => $level,
|
||||
@ -248,9 +257,9 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
"line_prefix" => $this->getLinePrefix(),
|
||||
"content" => $content,
|
||||
];
|
||||
$key = array_key_last($this->titles);
|
||||
if ($key !== null) {
|
||||
$title =& $this->titles[$key];
|
||||
$title = $this->title__last();
|
||||
if ($title !== null) {
|
||||
$title =& $this->title__ref();
|
||||
$title["descs"][] = $desc;
|
||||
$title["print_descs"] = true;
|
||||
} else {
|
||||
@ -263,16 +272,21 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
|
||||
protected array $actions;
|
||||
|
||||
protected function action__last(): ?array {
|
||||
$last = end($this->actions);
|
||||
return $last !== false? $last: null;
|
||||
}
|
||||
|
||||
function action__getMarks(): array {
|
||||
return [count($this->actions)];
|
||||
}
|
||||
|
||||
protected function action__getId(): ?int {
|
||||
return end($this->actions)["id"] ?? null;
|
||||
return $this->action__last()["id"] ?? null;
|
||||
}
|
||||
|
||||
protected function action__end(?int $until=null): void {
|
||||
$action = $this->actions[array_key_last($this->actions)] ?? null;
|
||||
$action = $this->action__last();
|
||||
if ($action !== null) {
|
||||
$until ??= $action["max_action_level"];
|
||||
$until ??= $this->action__getMarks()[0] - 1;
|
||||
@ -320,6 +334,7 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
false, null,
|
||||
true, $rsuccess, $rcontent);
|
||||
}
|
||||
$action["action_aresult"] = true;
|
||||
} elseif ($printContent) {
|
||||
$this->_printAction(
|
||||
$level, $linePrefix, $indentLevel,
|
||||
@ -333,13 +348,19 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
if ($endAction) $this->action__end();
|
||||
}
|
||||
|
||||
protected function &action__ref(): ?array {
|
||||
return $this->actions[array_key_last($this->actions)];
|
||||
}
|
||||
|
||||
function action__beforeFunc(array $marks): void {
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
$action =& $this->action__ref();
|
||||
$action["max_action_level"] = $marks[0] + 1;
|
||||
}
|
||||
|
||||
function action__afterFunc(array $marks): void {
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
function action__afterFunc(array $marks, $result): void {
|
||||
$action =& $this->action__ref();
|
||||
$aresult = $action["action_aresult"] ?? false;
|
||||
if (!$aresult) $this->aresult($result);
|
||||
$action["max_action_level"] = null;
|
||||
$this->action__end($marks[0]);
|
||||
}
|
||||
@ -349,9 +370,10 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
$marks = $this->action__getMarks();
|
||||
// faire en deux temps pour linePrefix soit à jour
|
||||
$this->actions[] = ["id" => $this->lastActionId++];
|
||||
A::merge($this->actions[array_key_last($this->actions)], [
|
||||
A::merge($this->action__ref(), [
|
||||
"action_level" => $marks[0],
|
||||
"max_action_level" => null,
|
||||
"action_aresult" => false,
|
||||
"timestamp" => time(),
|
||||
"msg_level" => $level,
|
||||
"line_prefix" => $this->getLinePrefix(),
|
||||
@ -362,16 +384,14 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
]);
|
||||
if ($func !== null) {
|
||||
try {
|
||||
$result = null;
|
||||
$this->action__beforeFunc($marks);
|
||||
$result = $func($this);
|
||||
if ($this->action__getMarks()[0] > $marks[0]) {
|
||||
$this->aresult($result);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->afailure($e);
|
||||
throw $e;
|
||||
} finally {
|
||||
$this->action__afterFunc($marks);
|
||||
$this->action__afterFunc($marks, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -384,7 +404,7 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
|
||||
function asuccess($content=null, ?int $overrideLevel=null): void {
|
||||
if (!$this->actions) $this->action(null);
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
$action =& $this->action__ref();
|
||||
$action["result_success"] = true;
|
||||
$action["result_content"] = $content;
|
||||
$this->action__flush(true, $overrideLevel);
|
||||
@ -392,7 +412,7 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
|
||||
function afailure($content=null, ?int $overrideLevel=null): void {
|
||||
if (!$this->actions) $this->action(null);
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
$action =& $this->action__ref();
|
||||
$action["result_success"] = false;
|
||||
$action["result_content"] = $content;
|
||||
$this->action__flush(true, $overrideLevel);
|
||||
@ -400,7 +420,7 @@ class ConsoleMessenger extends AbstractMessenger {
|
||||
|
||||
function adone($content=null, ?int $overrideLevel=null): void {
|
||||
if (!$this->actions) $this->action(null);
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
$action =& $this->action__ref();
|
||||
$action["result_success"] = null;
|
||||
$action["result_content"] = $content;
|
||||
$this->action__flush(true, $overrideLevel);
|
||||
|
@ -104,16 +104,21 @@ class LogMessenger extends AbstractMessenger {
|
||||
|
||||
protected array $titles;
|
||||
|
||||
protected function title__last(): ?array {
|
||||
$last = end($this->titles);
|
||||
return $last !== false? $last: null;
|
||||
}
|
||||
|
||||
function title__getMarks(): array {
|
||||
return [count($this->titles)];
|
||||
}
|
||||
|
||||
protected function title__getId(): ?int {
|
||||
return end($this->titles)["id"] ?? null;
|
||||
return $this->title__last()["id"] ?? null;
|
||||
}
|
||||
|
||||
protected function title__end(?int $until=null): void {
|
||||
$title = $this->titles[array_key_last($this->titles)] ?? null;
|
||||
$title = $this->title__last();
|
||||
if ($title !== null) {
|
||||
$until ??= $title["max_title_level"];
|
||||
$until ??= $this->title__getMarks()[0] - 1;
|
||||
@ -123,13 +128,17 @@ class LogMessenger extends AbstractMessenger {
|
||||
}
|
||||
}
|
||||
|
||||
protected function &title__ref(): ?array {
|
||||
return $this->titles[array_key_last($this->titles)];
|
||||
}
|
||||
|
||||
function title__beforeFunc(array $marks): void {
|
||||
$title =& $this->titles[array_key_last($this->titles)];
|
||||
$title =& $this->title__ref();
|
||||
$title["max_title_level"] = $marks[0] + 1;
|
||||
}
|
||||
|
||||
function title__afterFunc(array $marks): void {
|
||||
$title =& $this->titles[array_key_last($this->titles)];
|
||||
$title =& $this->title__ref();
|
||||
$title["max_title_level"] = null;
|
||||
$this->title__end($marks[0]);
|
||||
}
|
||||
@ -157,7 +166,7 @@ class LogMessenger extends AbstractMessenger {
|
||||
|
||||
function desc($content, ?int $level=null): void {
|
||||
if (!$this->checkLevel($level)) return;
|
||||
$titleLevel = end($this->titles)["title_level"] ?? 0;
|
||||
$titleLevel = $this->title__last()["title_level"] ?? 0;
|
||||
$this->_printGeneric(
|
||||
$level, "desc", $this->getLinePrefix(), $titleLevel,
|
||||
$this->out, $content);
|
||||
@ -165,16 +174,21 @@ class LogMessenger extends AbstractMessenger {
|
||||
|
||||
protected array $actions;
|
||||
|
||||
protected function action__last(): ?array {
|
||||
$last = end($this->actions);
|
||||
return $last !== false? $last: null;
|
||||
}
|
||||
|
||||
function action__getMarks(): array {
|
||||
return [count($this->actions)];
|
||||
}
|
||||
|
||||
protected function action__getId(): ?int {
|
||||
return end($this->actions)["id"] ?? null;
|
||||
return $this->action__last()["id"] ?? null;
|
||||
}
|
||||
|
||||
protected function action__end(?int $until=null): void {
|
||||
$action = $this->actions[array_key_last($this->actions)] ?? null;
|
||||
$action = $this->action__last();
|
||||
if ($action !== null) {
|
||||
$until ??= $action["max_action_level"];
|
||||
$until ??= $this->action__getMarks()[0] - 1;
|
||||
@ -187,13 +201,19 @@ class LogMessenger extends AbstractMessenger {
|
||||
protected function action__flush(bool $endAction=false, ?int $overrideLevel=null): void {
|
||||
}
|
||||
|
||||
protected function &action__ref(): ?array {
|
||||
return $this->actions[array_key_last($this->actions)];
|
||||
}
|
||||
|
||||
function action__beforeFunc(array $marks): void {
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
$action =& $this->action__ref();
|
||||
$action["max_action_level"] = $marks[0] + 1;
|
||||
}
|
||||
|
||||
function action__afterFunc(array $marks): void {
|
||||
$action =& $this->actions[array_key_last($this->actions)];
|
||||
function action__afterFunc(array $marks, $result): void {
|
||||
$action =& $this->action__ref();
|
||||
$aresult = $action["action_aresult"] ?? false;
|
||||
if (!$aresult) $this->aresult($result);
|
||||
$action["max_action_level"] = null;
|
||||
$this->action__end($marks[0]);
|
||||
}
|
||||
@ -205,6 +225,7 @@ class LogMessenger extends AbstractMessenger {
|
||||
"id" => $this->lastActionId++,
|
||||
"action_level" => $marks[0],
|
||||
"max_action_level" => null,
|
||||
"action_aresult" => false,
|
||||
"msg_level" => $level
|
||||
];
|
||||
$this->_printAction(
|
||||
@ -214,16 +235,14 @@ class LogMessenger extends AbstractMessenger {
|
||||
false, null, null);
|
||||
if ($func !== null) {
|
||||
try {
|
||||
$result = null;
|
||||
$this->action__beforeFunc($marks);
|
||||
$result = $func($this);
|
||||
if ($this->action__getMarks()[0] > $marks[0]) {
|
||||
$this->aresult($result);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->afailure($e);
|
||||
throw $e;
|
||||
} finally {
|
||||
$this->action__afterFunc($marks);
|
||||
$this->action__afterFunc($marks, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -236,37 +255,40 @@ class LogMessenger extends AbstractMessenger {
|
||||
|
||||
function asuccess($content=null, ?int $overrideLevel=null): void {
|
||||
if ($this->action__getMarks()[0] == 0) $this->action(null);
|
||||
$action = end($this->actions);
|
||||
$action =& $this->action__ref();
|
||||
$level = $overrideLevel ?? $action["msg_level"];
|
||||
$this->_printAction(
|
||||
$level, $this->getLinePrefix(), $action["action_level"],
|
||||
$this->out,
|
||||
false, null,
|
||||
true, true, $content);
|
||||
$action["action_aresult"] = true;
|
||||
$this->action__end();
|
||||
}
|
||||
|
||||
function afailure($content=null, ?int $overrideLevel=null): void {
|
||||
if ($this->action__getMarks()[0] == 0) $this->action(null);
|
||||
$action = end($this->actions);
|
||||
$action =& $this->action__ref();
|
||||
$level = $overrideLevel ?? $action["msg_level"];
|
||||
$this->_printAction(
|
||||
$level, $this->getLinePrefix(), $action["action_level"],
|
||||
$this->out,
|
||||
false, null,
|
||||
true, false, $content);
|
||||
$action["action_aresult"] = true;
|
||||
$this->action__end();
|
||||
}
|
||||
|
||||
function adone($content=null, ?int $overrideLevel=null): void {
|
||||
if ($this->action__getMarks()[0] == 0) $this->action(null);
|
||||
$action = end($this->actions);
|
||||
$action =& $this->action__ref();
|
||||
$level = $overrideLevel ?? $action["msg_level"];
|
||||
$this->_printAction(
|
||||
$level, $this->getLinePrefix(), $action["action_level"],
|
||||
$this->out,
|
||||
false, null,
|
||||
true, null, $content);
|
||||
$action["action_aresult"] = true;
|
||||
$this->action__end();
|
||||
}
|
||||
|
||||
|
@ -129,10 +129,10 @@ class ProxyMessenger implements _IMessenger {
|
||||
}
|
||||
}
|
||||
|
||||
function action__afterFunc(array $marks): void {
|
||||
function action__afterFunc(array $marks, $result): void {
|
||||
foreach ($this->msgs as $key => $msg) {
|
||||
if ($msg instanceof _IMessenger) {
|
||||
$msg->action__afterFunc($marks[$key]);
|
||||
$msg->action__afterFunc($marks[$key], $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,10 +144,11 @@ class ProxyMessenger implements _IMessenger {
|
||||
}
|
||||
if ($func !== null) {
|
||||
try {
|
||||
$result = null;
|
||||
$this->action__beforeFunc($marks);
|
||||
$func($this);
|
||||
$result = $func($this);
|
||||
} finally {
|
||||
$this->action__afterFunc($marks);
|
||||
$this->action__afterFunc($marks, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,5 +88,5 @@ interface _IMessenger extends IMessenger {
|
||||
/** @param int[] $marks */
|
||||
function action__beforeFunc(array $marks): void;
|
||||
/** @param int[] $marks */
|
||||
function action__afterFunc(array $marks): void;
|
||||
function action__afterFunc(array $marks, $result): void;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user