suivi action

This commit is contained in:
Jephté Clain 2024-05-16 18:03:21 +04:00
parent 4d883690cb
commit 502331664e
2 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
namespace nur\sery\output\std; namespace nur\sery\output\std;
use Exception;
use nur\sery\output\IMessenger; use nur\sery\output\IMessenger;
/** /**
@ -83,7 +84,21 @@ class ProxyMessenger implements IMessenger {
} }
if ($useFunc && $func !== null) { if ($useFunc && $func !== null) {
try { try {
$func($this); $result = $func($this);
if ($result !== null) {
/** @var _IMessenger $msg */
foreach ($this->msgs as $msg) {
if ($result === true) $msg->asuccess();
elseif ($result === false) $msg->afailure();
else $msg->adone($result);
}
}
} catch (Exception $e) {
/** @var _IMessenger $msg */
foreach ($this->msgs as $msg) {
$msg->afailure($e);
}
throw $e;
} finally { } finally {
/** @var _IMessenger $msg */ /** @var _IMessenger $msg */
$index = 0; $index = 0;

View File

@ -14,21 +14,21 @@ Application::run(new class extends Application {
msg::action("second", function (IMessenger $msg) { msg::action("second", function (IMessenger $msg) {
msg::action("third", function (IMessenger $msg) { msg::action("third", function (IMessenger $msg) {
$msg->info("hello world"); $msg->info("hello world");
$msg->asuccess(null, msg::DEBUG); $msg->asuccess();
}); });
$msg->asuccess(); $msg->asuccess();
}); });
$msg->asuccess(null, msg::DEBUG); $msg->asuccess();
}); });
msg::action("first2", function (IMessenger $msg) { msg::action("first2", function (IMessenger $msg) {
msg::action("second2", function (IMessenger $msg) { msg::action("second2", function (IMessenger $msg) {
msg::action("third2", function (IMessenger $msg) { msg::action("third2", function (IMessenger $msg) {
$msg->info("hello world2"); $msg->info("hello world2");
$msg->asuccess(null, msg::DEBUG); $msg->asuccess();
}); });
$msg->asuccess(); $msg->asuccess();
}); });
$msg->asuccess(null, msg::DEBUG); $msg->asuccess();
}); });
} }
}); });