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 */
16 * @see PhpXmlRpc\Wrapper::php_2_xmlrpc_type
17 * @param string $phpType
20 function php_2_xmlrpc_type($phpType)
22 $wrapper = new PhpXmlRpc\Wrapper();
23 return $wrapper->php2XmlrpcType($phpType);
27 * @see PhpXmlRpc\Wrapper::xmlrpc_2_php_type
28 * @param string $xmlrpcType
31 function xmlrpc_2_php_type($xmlrpcType)
33 $wrapper = new PhpXmlRpc\Wrapper();
34 return $wrapper->xmlrpc2PhpType($xmlrpcType);
37 /// @todo backwards compat: return string instead of callable
39 * @see PhpXmlRpc\Wrapper::wrap_php_function
40 * @param callable $funcName
41 * @param string $newFuncName
42 * @param array $extraOptions
45 function wrap_php_function($funcName, $newFuncName='', $extraOptions=array())
47 $wrapper = new PhpXmlRpc\Wrapper();
48 return $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions);
51 /// @todo backwards compat: return strings instead of callables
53 * @see PhpXmlRpc\Wrapper::wrap_php_class
54 * @param string|object $className
55 * @param array $extraOptions
58 function wrap_php_class($className, $extraOptions=array())
60 $wrapper = new PhpXmlRpc\Wrapper();
61 return $wrapper->wrapPhpClass($className, $extraOptions);
64 /// @todo backwards compat: return string instead of callable
66 * @see PhpXmlRpc\Wrapper::wrapXmlrpcMethod
67 * @param xmlrpc_client $client
68 * @param string $methodName
69 * @param int|array $extraOptions the usage of an int as signature number is deprecated, use an option in $extraOptions
70 * @param int $timeout deprecated, use an option in $extraOptions
71 * @param string $protocol deprecated, use an option in $extraOptions
72 * @param string $newFuncName deprecated, use an option in $extraOptions
73 * @return array|callable|false
75 function wrap_xmlrpc_method($client, $methodName, $extraOptions=0, $timeout=0, $protocol='', $newFuncName='')
77 if (!is_array($extraOptions))
79 $sigNum = $extraOptions;
80 $extraOptions = array(
82 'timeout' => $timeout,
83 'protocol' => $protocol,
84 'new_function_name' => $newFuncName
88 $wrapper = new PhpXmlRpc\Wrapper();
89 return $wrapper->wrapXmlrpcMethod($client, $methodName, $extraOptions);
92 /// @todo backwards compat: return strings instead of callables
94 * @see PhpXmlRpc\Wrapper::wrap_xmlrpc_server
95 * @param xmlrpc_client $client
96 * @param array $extraOptions
99 function wrap_xmlrpc_server($client, $extraOptions=array())
101 $wrapper = new PhpXmlRpc\Wrapper();
102 return $wrapper->wrapXmlrpcServer($client, $extraOptions);
105 /// @todo fix dangling usage of $this->
107 * Given the necessary info, build php code that creates a new function to invoke a remote xmlrpc method.
108 * Take care that no full checking of input parameters is done to ensure that valid php code is emitted.
109 * Only kept for backwards compatibility
110 * Note: real spaghetti code follows...
114 function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName,
115 $mSig, $mDesc = '', $timeout = 0, $protocol = '', $clientCopyMode = 0, $prefix = 'xmlrpc',
116 $decodePhpObjects = false, $encodePhpObjects = false, $decodeFault = false,
117 $faultResponse = '', $namespace = '\\PhpXmlRpc\\')
119 $code = "function $xmlrpcFuncName (";
120 if ($clientCopyMode < 2) {
121 // client copy mode 0 or 1 == partial / full client copy in emitted code
122 $innerCode = build_client_wrapper_code($client, $clientCopyMode, $prefix, $namespace);
123 $innerCode .= "\$client->setDebug(\$debug);\n";
126 // client copy mode 2 == no client copy in emitted code
130 $innerCode .= "\$req = new {$namespace}Request('$methodName');\n";
133 // take care that PHP comment is not terminated unwillingly by method description
134 $mDesc = "/**\n* " . str_replace('*/', '* /', $mDesc) . "\n";
136 $mDesc = "/**\nFunction $xmlrpcFuncName\n";
140 $innerCode .= "\$encoder = new {$namespace}Encoder();\n";
142 $pCount = count($mSig);
143 for ($i = 1; $i < $pCount; $i++) {
146 if ($pType == 'i4' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' ||
147 $pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null'
149 // only build directly xmlrpc values when type is known and scalar
150 $innerCode .= "\$p$i = new {$namespace}Value(\$p$i, '$pType');\n";
152 if ($encodePhpObjects) {
153 $innerCode .= "\$p$i = \$encoder->encode(\$p$i, array('encode_php_objs'));\n";
155 $innerCode .= "\$p$i = \$encoder->encode(\$p$i);\n";
158 $innerCode .= "\$req->addparam(\$p$i);\n";
159 $mDesc .= '* @param ' . xmlrpc_2_php_type($pType) . " \$p$i\n";
161 if ($clientCopyMode < 2) {
162 $plist[] = '$debug=0';
163 $mDesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
165 $plist = implode(', ', $plist);
166 $mDesc .= '* @return ' . xmlrpc_2_php_type($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n";
168 $innerCode .= "\$res = \${$this_}client->send(\$req, $timeout, '$protocol');\n";
170 if (is_string($faultResponse) && ((strpos($faultResponse, '%faultCode%') !== false) || (strpos($faultResponse, '%faultString%') !== false))) {
171 $respCode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '" . str_replace("'", "''", $faultResponse) . "')";
173 $respCode = var_export($faultResponse, true);
178 if ($decodePhpObjects) {
179 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));";
181 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value());";
184 $code = $code . $plist . ") {\n" . $innerCode . "\n}\n";
186 return array('source' => $code, 'docstring' => $mDesc);
192 function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
194 $code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
195 "', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
197 // copy all client fields to the client that will be generated runtime
198 // (this provides for future expansion or subclassing of client obj)
199 if ($verbatim_client_copy)
201 foreach($client as $fld => $val)
203 if($fld != 'debug' && $fld != 'return_type')
205 $val = var_export($val, true);
206 $code .= "\$client->$fld = $val;\n";
210 // only make sure that client always returns the correct data type
211 $code .= "\$client->return_type = '{$prefix}vals';\n";
212 //$code .= "\$client->setDebug(\$debug);\n";