$catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';\r
\r
$exists = false;\r
- if (is_string($funcname) && strpos($funcname, '::') !== false)\r
- {\r
- $funcname = explode('::', $funcname);\r
- }\r
- if(is_array($funcname))\r
- {\r
- if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))\r
- {\r
- error_log('XML-RPC: syntax for function to be wrapped is wrong');\r
- return false;\r
- }\r
- if(is_string($funcname[0]))\r
- {\r
- $plainfuncname = implode('::', $funcname);\r
- }\r
- elseif(is_object($funcname[0]))\r
- {\r
- $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];\r
- }\r
- $exists = method_exists($funcname[0], $funcname[1]);\r
- }\r
- else\r
- {\r
- $plainfuncname = $funcname;\r
- $exists = function_exists($funcname);\r
- }\r
+ if (is_string($funcname) && strpos($funcname, '::') !== false)\r
+ {\r
+ $funcname = explode('::', $funcname);\r
+ }\r
+ if(is_array($funcname))\r
+ {\r
+ if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))\r
+ {\r
+ error_log('XML-RPC: syntax for function to be wrapped is wrong');\r
+ return false;\r
+ }\r
+ if(is_string($funcname[0]))\r
+ {\r
+ $plainfuncname = implode('::', $funcname);\r
+ }\r
+ elseif(is_object($funcname[0]))\r
+ {\r
+ $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];\r
+ }\r
+ $exists = method_exists($funcname[0], $funcname[1]);\r
+ }\r
+ else\r
+ {\r
+ $plainfuncname = $funcname;\r
+ $exists = function_exists($funcname);\r
+ }\r
\r
if(!$exists)\r
{\r
{\r
if(is_array($funcname))\r
{\r
- if(is_string($funcname[0]))\r
- $xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);\r
- else\r
- $xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];\r
+ if(is_string($funcname[0]))\r
+ $xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);\r
+ else\r
+ $xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];\r
}\r
else\r
{\r
// start to introspect PHP code\r
if(is_array($funcname))\r
{\r
- $func = new ReflectionMethod($funcname[0], $funcname[1]);\r
- if($func->isPrivate())\r
- {\r
- error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);\r
- return false;\r
- }\r
- if($func->isProtected())\r
- {\r
- error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);\r
- return false;\r
- }\r
- if($func->isConstructor())\r
- {\r
- error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);\r
- return false;\r
- }\r
- if($func->isDestructor())\r
- {\r
- error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);\r
- return false;\r
- }\r
- if($func->isAbstract())\r
- {\r
- error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);\r
- return false;\r
- }\r
- /// @todo add more checks for static vs. nonstatic?\r
- }\r
+ $func = new ReflectionMethod($funcname[0], $funcname[1]);\r
+ if($func->isPrivate())\r
+ {\r
+ error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);\r
+ return false;\r
+ }\r
+ if($func->isProtected())\r
+ {\r
+ error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);\r
+ return false;\r
+ }\r
+ if($func->isConstructor())\r
+ {\r
+ error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);\r
+ return false;\r
+ }\r
+ if($func->isDestructor())\r
+ {\r
+ error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);\r
+ return false;\r
+ }\r
+ if($func->isAbstract())\r
+ {\r
+ error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);\r
+ return false;\r
+ }\r
+ /// @todo add more checks for static vs. nonstatic?\r
+ }\r
else\r
{\r
- $func = new ReflectionFunction($funcname);\r
- }\r
+ $func = new ReflectionFunction($funcname);\r
+ }\r
if($func->isInternal())\r
{\r
// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs\r
\r
$innercode .= "\$np = false;\n";\r
// since there are no closures in php, if we are given an object instance,\r
- // we store a pointer to it in a global var...\r
+ // we store a pointer to it in a global var...\r
if ( is_array($funcname) && is_object($funcname[0]) )\r
{\r
- $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];\r
- $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";\r
- $realfuncname = '$obj->'.$funcname[1];\r
+ $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];\r
+ $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";\r
+ $realfuncname = '$obj->'.$funcname[1];\r
}\r
else\r
{\r
- $realfuncname = $plainfuncname;\r
- }\r
+ $realfuncname = $plainfuncname;\r
+ }\r
foreach($parsvariations as $pars)\r
{\r
$innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";\r
}\r
}\r
\r
- /**\r
- * Given a user-defined PHP class or php object, map its methods onto a list of\r
+ /**\r
+ * Given a user-defined PHP class or php object, map its methods onto a list of\r
* PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server\r
* object and called from remote clients (as well as their corresponding signature info).\r
*\r
- * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class\r
- * @param array $extra_options see the docs for wrap_php_method for more options\r
- * string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance\r
- * @return array or false on failure\r
- *\r
- * @todo get_class_methods will return both static and non-static methods.\r
- * we have to differentiate the action, depending on wheter we recived a class name or object\r
- */\r
- function wrap_php_class($classname, $extra_options=array())\r
- {\r
+ * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class\r
+ * @param array $extra_options see the docs for wrap_php_method for more options\r
+ * string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance\r
+ * @return array or false on failure\r
+ *\r
+ * @todo get_class_methods will return both static and non-static methods.\r
+ * we have to differentiate the action, depending on whether we received a class name or object\r
+ */\r
+ function wrap_php_class($classname, $extra_options=array())\r
+ {\r
$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';\r
$methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';\r
\r
- $result = array();\r
+ $result = array();\r
$mlist = get_class_methods($classname);\r
foreach($mlist as $mname)\r
{\r
- if ($methodfilter == '' || preg_match($methodfilter, $mname))\r
- {\r
- // echo $mlist."\n";\r
- $func = new ReflectionMethod($classname, $mname);\r
- if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())\r
- {\r
- if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||\r
- (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))\r
- {\r
- $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);\r
- if ( $methodwrap )\r
- {\r
- $result[$methodwrap['function']] = $methodwrap['function'];\r
- }\r
- }\r
- }\r
+ if ($methodfilter == '' || preg_match($methodfilter, $mname))\r
+ {\r
+ // echo $mlist."\n";\r
+ $func = new ReflectionMethod($classname, $mname);\r
+ if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())\r
+ {\r
+ if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||\r
+ (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))\r
+ {\r
+ $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);\r
+ if ( $methodwrap )\r
+ {\r
+ $result[$methodwrap['function']] = $methodwrap['function'];\r
+ }\r
+ }\r
+ }\r
}\r
}\r
- return $result;\r
- }\r
+ return $result;\r
+ }\r
\r
/**\r
* Given an xmlrpc client and a method name, register a php wrapper function\r