3 /******************************************************************************
7 * This file is only used to insure backwards compatibility
8 * with the API of the library <= rev. 3
9 *****************************************************************************/
11 include_once(__DIR__.'/../src/Wrapper.php');
13 /* Expose as global functions the ones which are now class methods */
15 function php_2_xmlrpc_type($phpType)
17 $wrapper = new PhpXmlRpc\Wrapper();
18 return $wrapper->php_2_xmlrpc_type($phpType);
21 function xmlrpc_2_php_type($xmlrpcType)
23 $wrapper = new PhpXmlRpc\Wrapper();
24 return $wrapper->xmlrpc_2_php_type($xmlrpcType);
27 /// @todo return string instead of callable
28 function wrap_php_function($funcName, $newFuncName='', $extraOptions=array())
30 $wrapper = new PhpXmlRpc\Wrapper();
31 return $wrapper->wrap_php_function($funcName, $newFuncName, $extraOptions);
34 /// @todo return strings instead of callables
35 function wrap_php_class($className, $extraOptions=array())
37 $wrapper = new PhpXmlRpc\Wrapper();
38 return $wrapper->wrap_php_class($className, $extraOptions);
41 /// @todo support different calling convention
42 /// @todo return string instead of callable
43 function wrap_xmlrpc_method($client, $methodName, $extraOptions=0, $timeout=0, $protocol='', $newFuncName='')
45 $wrapper = new PhpXmlRpc\Wrapper();
46 return $wrapper->wrap_xmlrpc_method($client, $methodName, $extraOptions, $timeout, $protocol, $newFuncName);
49 /// @todo return strings instead of callables
50 function wrap_xmlrpc_server($client, $extraOptions=array())
52 $wrapper = new PhpXmlRpc\Wrapper();
53 return $wrapper->wrap_xmlrpc_server($client, $extraOptions);
57 * Given the necessary info, build php code that creates a new function to invoke a remote xmlrpc method.
58 * Take care that no full checking of input parameters is done to ensure that valid php code is emitted.
59 * Only kept for backwards compatibility
60 * Note: real spaghetti code follows...
64 function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName,
65 $mSig, $mDesc = '', $timeout = 0, $protocol = '', $clientCopyMode = 0, $prefix = 'xmlrpc',
66 $decodePhpObjects = false, $encodePhpObjects = false, $decodeFault = false,
67 $faultResponse = '', $namespace = '\\PhpXmlRpc\\')
69 $code = "function $xmlrpcFuncName (";
70 if ($clientCopyMode < 2) {
71 // client copy mode 0 or 1 == partial / full client copy in emitted code
72 $innerCode = $this->build_client_wrapper_code($client, $clientCopyMode, $prefix, $namespace);
73 $innerCode .= "\$client->setDebug(\$debug);\n";
76 // client copy mode 2 == no client copy in emitted code
80 $innerCode .= "\$req = new {$namespace}Request('$methodName');\n";
83 // take care that PHP comment is not terminated unwillingly by method description
84 $mDesc = "/**\n* " . str_replace('*/', '* /', $mDesc) . "\n";
86 $mDesc = "/**\nFunction $xmlrpcFuncName\n";
90 $innerCode .= "\$encoder = new {$namespace}Encoder();\n";
92 $pCount = count($mSig);
93 for ($i = 1; $i < $pCount; $i++) {
96 if ($pType == 'i4' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' ||
97 $pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null'
99 // only build directly xmlrpc values when type is known and scalar
100 $innerCode .= "\$p$i = new {$namespace}Value(\$p$i, '$pType');\n";
102 if ($encodePhpObjects) {
103 $innerCode .= "\$p$i = \$encoder->encode(\$p$i, array('encode_php_objs'));\n";
105 $innerCode .= "\$p$i = \$encoder->encode(\$p$i);\n";
108 $innerCode .= "\$req->addparam(\$p$i);\n";
109 $mDesc .= '* @param ' . $this->xmlrpc_2_php_type($pType) . " \$p$i\n";
111 if ($clientCopyMode < 2) {
112 $plist[] = '$debug=0';
113 $mDesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
115 $plist = implode(', ', $plist);
116 $mDesc .= '* @return ' . $this->xmlrpc_2_php_type($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n";
118 $innerCode .= "\$res = \${$this_}client->send(\$req, $timeout, '$protocol');\n";
120 if (is_string($faultResponse) && ((strpos($faultResponse, '%faultCode%') !== false) || (strpos($faultResponse, '%faultString%') !== false))) {
121 $respCode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '" . str_replace("'", "''", $faultResponse) . "')";
123 $respCode = var_export($faultResponse, true);
128 if ($decodePhpObjects) {
129 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));";
131 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value());";
134 $code = $code . $plist . ") {\n" . $innerCode . "\n}\n";
136 return array('source' => $code, 'docstring' => $mDesc);