Add try/catch call_user_func

This commit is contained in:
cmp167
2024-03-21 17:43:16 +03:00
parent d178d52aa6
commit 1c147024e5

View File

@@ -351,15 +351,47 @@
if(!isset($opt["silent"]) || !$opt["silent"])
$this->d($prs["streamCurrent"] . ": " . $a[$i]);
$callName = "";
if($prs["streamCurrent"] == "stdout") {
if(isset($opt["eventStringStdOut"]) && $opt["eventStringStdOut"]) {
($opt["eventStringStdOut"]["call"])($a[$i], $prs);
}
$callName = "eventStringStdOut";
}
else if($prs["streamCurrent"] == "stderr") {
if(isset($opt["eventStringStdErr"]) && $opt["eventStringStdErr"]) {
($opt["eventStringStdErr"]["call"])($a[$i], $prs);
}
$callName = "eventStringStdErr";
}
if(!isset($opt["eventStringStdOut"]))
continue;
if(!$opt["eventStringStdOut"])
continue;
if(!isset($opt[$callName]["call"])) {
$this->d("Unset $callName.call");
continue;
}
if(!is_callable($opt[$callName]["call"])) {
$this->d("Uncallable $callName.call");
continue;
}
$parm = null;
if(isset($opt[$callName]["parm"]))
$parm = $opt[$callName]["parm"];
try {
$ret = call_user_func(
$opt[$callName]["call"],
array(
"string" => $a[$i],
"parm" => $parm,
"prs" => $prs
)
);
} catch(Exception | Error $e) {
$this->e($e);
}
}
@@ -651,7 +683,10 @@
$this->cmpSysExec($a, array(
"silent" => false,
"eventString" => true,
"eventStringStdOut" => array("call" => [$this, "d"])
"eventStringStdOut" => array(
"call" => [$this, "d"],
"parm" => "testparm"
)
));
}