From e4ed1ac5b024cbbcc9e8ccea39f8d8af8fa49496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Tue, 1 Nov 2005 14:19:00 +0000 Subject: [PATCH] add execmethod2 which could handle multiple arguments There was no way of patching the existing ExecMethod, as Felamimail, emailadmin and ldapadmin depend on the class consturction of this method --- phpgwapi/inc/common_functions.inc.php | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index afd461d58d..2cfba7496b 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -711,6 +711,44 @@ return $obj; } + /** + * Execute a function with multiple arguments + * We take object $GLOBALS[classname] from class if exists + * + * @param string app.class.method method to execute + * @example ExecObject('etemplates.so_sql.search',$criteria,$key_only,...); + */ + function &ExecMethod2($acm) + { + list($app,$class,$method) = explode('.',$acm); + if (!is_object($obj =& $GLOBALS[$class])) + { + $newobj = 1; + $obj =& CreateObject($acm); + } + + if (!method_exists($obj,$method)) + { + echo "

".function_backtrace().": no methode '$method' in class '$class'

\n"; + return False; + } + + $args = func_get_args(); + unset($args[0]); + $code = '$return = $obj->'.$method.'('; + foreach ($args as $n => $arg) + { + if ($n) + { + $code .= ($n > 1 ? ',' : '') . '$args[' . $n . ']'; + } + } + + eval($code.');'); + if($newobj) unset($obj); + return $return; + } + /*! @function ExecMethod @abstract Execute a function, and load a class and include the class file if not done so already.