pass up to 2 parameters when calling hook

This commit is contained in:
Uwe Steinmann 2013-07-31 17:28:02 +02:00
parent 7fba6dda6d
commit 1451659ba2

View File

@ -58,16 +58,36 @@ class SeedDMS_View_Common {
function show() {
}
/**
* Call a hook with a given name
*
* Checks if a hook with the given name and for the current view
* exists and executes it. The name of the current view 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.
*
* @params string $hook name of hook
* @return mixed whatever the hook function returns
*/
function callHook($hook) {
$tmp = explode('_', get_class($this));
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])] as $hookObj) {
if (method_exists($hookObj, $hook)) {
return $hookObj->$hook($this);
switch(func_num_args()) {
case 1:
return $hookObj->$hook($this);
case 2:
return $hookObj->$hook($this, func_get_arg(1));
case 3:
default:
return $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
}
}
}
}
return "";
return null;
}
}
?>