callHook merges strings and arrays returned from hook

This commit is contained in:
Uwe Steinmann 2021-07-08 14:14:13 +02:00
parent 8a7fb230da
commit e0a12590da

View File

@ -231,6 +231,7 @@ class SeedDMS_Controller_Common {
*/ */
function callHook($hook) { /* {{{ */ function callHook($hook) { /* {{{ */
$tmps = $this->getHookClassNames(); $tmps = $this->getHookClassNames();
$ret = null;
foreach($tmps as $tmp) foreach($tmps as $tmp)
if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp)])) { if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp)])) {
$this->lasthookresult = null; $this->lasthookresult = null;
@ -238,29 +239,35 @@ class SeedDMS_Controller_Common {
if (method_exists($hookObj, $hook)) { if (method_exists($hookObj, $hook)) {
switch(func_num_args()) { switch(func_num_args()) {
case 4: case 4:
$result = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3)); $tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3));
break; break;
case 3: case 3:
$result = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2)); $tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
break; break;
case 2: case 2:
$result = $hookObj->$hook($this, func_get_arg(1)); $tmpret = $hookObj->$hook($this, func_get_arg(1));
break; break;
case 1: case 1:
default: default:
$result = $hookObj->$hook($this); $tmpret = $hookObj->$hook($this);
} }
if($result === false) { if($tmpret === false) {
return $result; return $tmpret;
} }
if($result !== null) { if($tmpret !== null) {
$this->lasthookresult = $result; $this->lasthookresult = $tmpret;
if(is_string($tmpret)) {
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? $ret.$tmpret : array_merge($ret, array($tmpret)));
} elseif(is_array($tmpret)) { // || is_object($tmpret)) {
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? array_merge(array($ret), $tmpret) : array_merge($ret, $tmpret));
} else
$ret = $tmpret;
} }
} }
} }
return $this->lasthookresult; // return $this->lasthookresult;
} }
return null; return $ret;
} /* }}} */ } /* }}} */
/** /**