mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
add method callHook() to class SeedDMS_SchedulerTaskBase
This commit is contained in:
parent
715f6ec04e
commit
f1aed51047
|
@ -39,6 +39,68 @@ class SeedDMS_SchedulerTaskBase {
|
|||
|
||||
var $fulltextservice;
|
||||
|
||||
/**
|
||||
* Call a hook with a given name
|
||||
*
|
||||
* Checks if a hook with the given name and for the current task
|
||||
* exists and executes it. The name of the current task is taken
|
||||
* from the current class name by lower casing the first char.
|
||||
* This function will execute all registered hooks in the order
|
||||
* they were registered.
|
||||
*
|
||||
* Attention: as func_get_arg() cannot handle references passed to the hook,
|
||||
* callHook() should not be called if that is required. In that case get
|
||||
* a list of hook objects with getHookObjects() and call the hooks yourself.
|
||||
*
|
||||
* @params string $hook name of hook
|
||||
* @return string concatenated string, merged arrays or whatever the hook
|
||||
* function returns
|
||||
*/
|
||||
public function callHook($hook) { /* {{{ */
|
||||
$tmps = array();
|
||||
$tmp = explode('_', get_class($this));
|
||||
$tmps[] = $tmp[1];
|
||||
$tmp = explode('_', get_parent_class($this));
|
||||
$tmps[] = $tmp[1];
|
||||
/* Run array_unique() in case the parent class has the same suffix */
|
||||
$tmps = array_unique($tmps);
|
||||
$ret = null;
|
||||
foreach($tmps as $tmp)
|
||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['task'][lcfirst($tmp)])) {
|
||||
foreach($GLOBALS['SEEDDMS_HOOKS']['task'][lcfirst($tmp)] as $hookObj) {
|
||||
if (method_exists($hookObj, $hook)) {
|
||||
switch(func_num_args()) {
|
||||
case 1:
|
||||
$tmpret = $hookObj->$hook($this);
|
||||
break;
|
||||
case 2:
|
||||
$tmpret = $hookObj->$hook($this, func_get_arg(1));
|
||||
break;
|
||||
case 3:
|
||||
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
|
||||
break;
|
||||
case 4:
|
||||
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3));
|
||||
break;
|
||||
default:
|
||||
case 5:
|
||||
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
|
||||
break;
|
||||
}
|
||||
if($tmpret !== null) {
|
||||
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 $ret;
|
||||
} /* }}} */
|
||||
|
||||
public function __construct($dms=null, $user=null, $settings=null, $logger=null, $fulltextservice=null) { /* {{{ */
|
||||
$this->dms = $dms;
|
||||
$this->user = $user;
|
||||
|
|
Loading…
Reference in New Issue
Block a user