Add try/catch call_user_func
This commit is contained in:
47
cmpUtil.php
47
cmpUtil.php
@@ -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"
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user