From 1451659ba245af841dc4a12969bc2c3590bdcf79 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 31 Jul 2013 17:28:02 +0200 Subject: [PATCH] pass up to 2 parameters when calling hook --- inc/inc.ClassViewCommon.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/inc/inc.ClassViewCommon.php b/inc/inc.ClassViewCommon.php index f497edd4f..86942d3ce 100644 --- a/inc/inc.ClassViewCommon.php +++ b/inc/inc.ClassViewCommon.php @@ -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; } } ?>