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);
38 * @see PhpXmlRpc\Wrapper::wrap_php_function
39 * @param callable $funcName
40 * @param string $newFuncName
41 * @param array $extraOptions
44 function wrap_php_function($funcName, $newFuncName='', $extraOptions=array())
46 $wrapper = new PhpXmlRpc\Wrapper();
47 if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) {
48 // backwards compat: return string instead of callable
49 $extraOptions['return_source'] = true;
50 $wrapped = $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions);
51 eval($wrapped['source']);
53 $wrapped = $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions);
59 * NB: this function returns an array in a format which is unsuitable for direct use in the server dispatch map, unlike
60 * PhpXmlRpc\Wrapper::wrapPhpClass. This behaviour might seem like a bug, but has been kept for backwards compatibility.
62 * @see PhpXmlRpc\Wrapper::wrap_php_class
63 * @param string|object $className
64 * @param array $extraOptions
67 function wrap_php_class($className, $extraOptions=array())
69 $wrapper = new PhpXmlRpc\Wrapper();
71 if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) {
72 // backwards compat: return string instead of callable
73 $extraOptions['return_source'] = true;
76 $wrapped = $wrapper->wrapPhpClass($className, $extraOptions);
77 foreach($wrapped as $name => $value) {
79 eval($value['source']);
81 $wrapped[$name] = $value['function'];
87 * @see PhpXmlRpc\Wrapper::wrapXmlrpcMethod
88 * @param xmlrpc_client $client
89 * @param string $methodName
90 * @param int|array $extraOptions the usage of an int as signature number is deprecated, use an option in $extraOptions
91 * @param int $timeout deprecated, use an option in $extraOptions
92 * @param string $protocol deprecated, use an option in $extraOptions
93 * @param string $newFuncName deprecated, use an option in $extraOptions
94 * @return array|callable|false
96 function wrap_xmlrpc_method($client, $methodName, $extraOptions=0, $timeout=0, $protocol='', $newFuncName='')
98 if (!is_array($extraOptions))
100 $sigNum = $extraOptions;
101 $extraOptions = array(
103 'timeout' => $timeout,
104 'protocol' => $protocol,
105 'new_function_name' => $newFuncName
109 $wrapper = new PhpXmlRpc\Wrapper();
111 if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) {
112 // backwards compat: return string instead of callable
113 $extraOptions['return_source'] = true;
114 $wrapped = $wrapper->wrapXmlrpcMethod($client, $methodName, $extraOptions);
115 eval($wrapped['source']);
116 $wrapped = $wrapped['function'];
118 $wrapped = $wrapper->wrapXmlrpcMethod($client, $methodName, $extraOptions);
124 * @see PhpXmlRpc\Wrapper::wrap_xmlrpc_server
125 * @param xmlrpc_client $client
126 * @param array $extraOptions
129 function wrap_xmlrpc_server($client, $extraOptions=array())
131 $wrapper = new PhpXmlRpc\Wrapper();
132 return $wrapper->wrapXmlrpcServer($client, $extraOptions);
136 * Given the necessary info, build php code that creates a new function to invoke a remote xmlrpc method.
137 * Take care that no full checking of input parameters is done to ensure that valid php code is emitted.
138 * Only kept for backwards compatibility
139 * Note: real spaghetti code follows...
143 function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName,
144 $mSig, $mDesc = '', $timeout = 0, $protocol = '', $clientCopyMode = 0, $prefix = 'xmlrpc',
145 $decodePhpObjects = false, $encodePhpObjects = false, $decodeFault = false,
146 $faultResponse = '', $namespace = '\\PhpXmlRpc\\')
148 $code = "function $xmlrpcFuncName (";
149 if ($clientCopyMode < 2) {
150 // client copy mode 0 or 1 == partial / full client copy in emitted code
151 $innerCode = build_client_wrapper_code($client, $clientCopyMode, $prefix, $namespace);
152 $innerCode .= "\$client->setDebug(\$debug);\n";
155 // client copy mode 2 == no client copy in emitted code
159 $innerCode .= "\$req = new {$namespace}Request('$methodName');\n";
162 // take care that PHP comment is not terminated unwillingly by method description
163 $mDesc = "/**\n* " . str_replace('*/', '* /', $mDesc) . "\n";
165 $mDesc = "/**\nFunction $xmlrpcFuncName\n";
169 $innerCode .= "\$encoder = new {$namespace}Encoder();\n";
171 $pCount = count($mSig);
172 for ($i = 1; $i < $pCount; $i++) {
175 if ($pType == 'i4' || $pType == 'i8' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' ||
176 $pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null'
178 // only build directly xmlrpc values when type is known and scalar
179 $innerCode .= "\$p$i = new {$namespace}Value(\$p$i, '$pType');\n";
181 if ($encodePhpObjects) {
182 $innerCode .= "\$p$i = \$encoder->encode(\$p$i, array('encode_php_objs'));\n";
184 $innerCode .= "\$p$i = \$encoder->encode(\$p$i);\n";
187 $innerCode .= "\$req->addparam(\$p$i);\n";
188 $mDesc .= '* @param ' . xmlrpc_2_php_type($pType) . " \$p$i\n";
190 if ($clientCopyMode < 2) {
191 $plist[] = '$debug=0';
192 $mDesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
194 $plist = implode(', ', $plist);
195 $mDesc .= '* @return ' . xmlrpc_2_php_type($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n";
197 $innerCode .= "\$res = \${$this_}client->send(\$req, $timeout, '$protocol');\n";
199 if (is_string($faultResponse) && ((strpos($faultResponse, '%faultCode%') !== false) || (strpos($faultResponse, '%faultString%') !== false))) {
200 $respCode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '" . str_replace("'", "''", $faultResponse) . "')";
202 $respCode = var_export($faultResponse, true);
207 if ($decodePhpObjects) {
208 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));";
210 $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value());";
213 $code = $code . $plist . ") {\n" . $innerCode . "\n}\n";
215 return array('source' => $code, 'docstring' => $mDesc);
221 function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
223 $code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
224 "', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
226 // copy all client fields to the client that will be generated runtime
227 // (this provides for future expansion or subclassing of client obj)
228 if ($verbatim_client_copy)
230 foreach($client as $fld => $val)
232 if($fld != 'debug' && $fld != 'return_type')
234 $val = var_export($val, true);
235 $code .= "\$client->$fld = $val;\n";
239 // only make sure that client always returns the correct data type
240 $code .= "\$client->return_type = '{$prefix}vals';\n";
241 //$code .= "\$client->setDebug(\$debug);\n";