X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fxmlrpc_wrappers.inc;h=3c2390a21506e23f139209e6e4f50812aeb466f3;hb=25cd0af7fd7f07459a9448be6b6454d0afde4fff;hp=fc178dc9c8e7bcbcd556d918c0961cf1ce7fcae2;hpb=891efe4262d3cc5a379e0454f1f92c9dbdade9f7;p=plcapi.git diff --git a/lib/xmlrpc_wrappers.inc b/lib/xmlrpc_wrappers.inc index fc178dc..3c2390a 100644 --- a/lib/xmlrpc_wrappers.inc +++ b/lib/xmlrpc_wrappers.inc @@ -2,7 +2,7 @@ /****************************************************************************** * - *** DEPRECATED *** + * *** DEPRECATED *** * * This file is only used to insure backwards compatibility * with the API of the library <= rev. 3 @@ -12,45 +12,124 @@ include_once(__DIR__.'/../src/Wrapper.php'); /* Expose as global functions the ones which are now class methods */ +/** + * @see PhpXmlRpc\Wrapper::php_2_xmlrpc_type + * @param string $phpType + * @return string + */ function php_2_xmlrpc_type($phpType) { $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->php_2_xmlrpc_type($phpType); + return $wrapper->php2XmlrpcType($phpType); } +/** + * @see PhpXmlRpc\Wrapper::xmlrpc_2_php_type + * @param string $xmlrpcType + * @return string + */ function xmlrpc_2_php_type($xmlrpcType) { $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->xmlrpc_2_php_type($xmlrpcType); + return $wrapper->xmlrpc2PhpType($xmlrpcType); } -/// @todo return string instead of callable +/** + * @see PhpXmlRpc\Wrapper::wrap_php_function + * @param callable $funcName + * @param string $newFuncName + * @param array $extraOptions + * @return array|false + */ function wrap_php_function($funcName, $newFuncName='', $extraOptions=array()) { $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->wrap_php_function($funcName, $newFuncName, $extraOptions); + if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) { + // backwards compat: return string instead of callable + $extraOptions['return_source'] = true; + $wrapped = $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions); + eval($wrapped['source']); + } else { + $wrapped = $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions); + } + return $wrapped; } -/// @todo return strings instead of callables +/** + * NB: this function returns an array in a format which is unsuitable for direct use in the server dispatch map, unlike + * PhpXmlRpc\Wrapper::wrapPhpClass. This behaviour might seem like a bug, but has been kept for backwards compatibility. + * + * @see PhpXmlRpc\Wrapper::wrap_php_class + * @param string|object $className + * @param array $extraOptions + * @return array|false + */ function wrap_php_class($className, $extraOptions=array()) { $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->wrap_php_class($className, $extraOptions); + $fix = false; + if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) { + // backwards compat: return string instead of callable + $extraOptions['return_source'] = true; + $fix = true; + } + $wrapped = $wrapper->wrapPhpClass($className, $extraOptions); + foreach($wrapped as $name => $value) { + if ($fix) { + eval($value['source']); + } + $wrapped[$name] = $value['function']; + } + return $wrapped; } -/// @todo support different calling convention -/// @todo return string instead of callable +/** + * @see PhpXmlRpc\Wrapper::wrapXmlrpcMethod + * @param xmlrpc_client $client + * @param string $methodName + * @param int|array $extraOptions the usage of an int as signature number is deprecated, use an option in $extraOptions + * @param int $timeout deprecated, use an option in $extraOptions + * @param string $protocol deprecated, use an option in $extraOptions + * @param string $newFuncName deprecated, use an option in $extraOptions + * @return array|callable|false + */ function wrap_xmlrpc_method($client, $methodName, $extraOptions=0, $timeout=0, $protocol='', $newFuncName='') { + if (!is_array($extraOptions)) + { + $sigNum = $extraOptions; + $extraOptions = array( + 'signum' => $sigNum, + 'timeout' => $timeout, + 'protocol' => $protocol, + 'new_function_name' => $newFuncName + ); + } + $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->wrap_xmlrpc_method($client, $methodName, $extraOptions, $timeout, $protocol, $newFuncName); + + if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) { + // backwards compat: return string instead of callable + $extraOptions['return_source'] = true; + $wrapped = $wrapper->wrapXmlrpcMethod($client, $methodName, $extraOptions); + eval($wrapped['source']); + $wrapped = $wrapped['function']; + } else { + $wrapped = $wrapper->wrapXmlrpcMethod($client, $methodName, $extraOptions); + } + return $wrapped; } -/// @todo return strings instead of callables +/** + * @see PhpXmlRpc\Wrapper::wrap_xmlrpc_server + * @param xmlrpc_client $client + * @param array $extraOptions + * @return mixed + */ function wrap_xmlrpc_server($client, $extraOptions=array()) { $wrapper = new PhpXmlRpc\Wrapper(); - return $wrapper->wrap_xmlrpc_server($client, $extraOptions); + return $wrapper->wrapXmlrpcServer($client, $extraOptions); } /** @@ -62,14 +141,14 @@ function wrap_xmlrpc_server($client, $extraOptions=array()) * @deprecated */ function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName, - $mSig, $mDesc = '', $timeout = 0, $protocol = '', $clientCopyMode = 0, $prefix = 'xmlrpc', - $decodePhpObjects = false, $encodePhpObjects = false, $decodeFault = false, - $faultResponse = '', $namespace = '\\PhpXmlRpc\\') + $mSig, $mDesc = '', $timeout = 0, $protocol = '', $clientCopyMode = 0, $prefix = 'xmlrpc', + $decodePhpObjects = false, $encodePhpObjects = false, $decodeFault = false, + $faultResponse = '', $namespace = '\\PhpXmlRpc\\') { $code = "function $xmlrpcFuncName ("; if ($clientCopyMode < 2) { // client copy mode 0 or 1 == partial / full client copy in emitted code - $innerCode = $this->build_client_wrapper_code($client, $clientCopyMode, $prefix, $namespace); + $innerCode = build_client_wrapper_code($client, $clientCopyMode, $prefix, $namespace); $innerCode .= "\$client->setDebug(\$debug);\n"; $this_ = ''; } else { @@ -106,14 +185,14 @@ function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName, } } $innerCode .= "\$req->addparam(\$p$i);\n"; - $mDesc .= '* @param ' . $this->xmlrpc_2_php_type($pType) . " \$p$i\n"; + $mDesc .= '* @param ' . xmlrpc_2_php_type($pType) . " \$p$i\n"; } if ($clientCopyMode < 2) { $plist[] = '$debug=0'; $mDesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n"; } $plist = implode(', ', $plist); - $mDesc .= '* @return ' . $this->xmlrpc_2_php_type($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n"; + $mDesc .= '* @return ' . xmlrpc_2_php_type($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n"; $innerCode .= "\$res = \${$this_}client->send(\$req, $timeout, '$protocol');\n"; if ($decodeFault) { @@ -135,3 +214,30 @@ function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName, return array('source' => $code, 'docstring' => $mDesc); } + +/** + * @deprecated + */ +function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc') +{ + $code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path). + "', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n"; + + // copy all client fields to the client that will be generated runtime + // (this provides for future expansion or subclassing of client obj) + if ($verbatim_client_copy) + { + foreach($client as $fld => $val) + { + if($fld != 'debug' && $fld != 'return_type') + { + $val = var_export($val, true); + $code .= "\$client->$fld = $val;\n"; + } + } + } + // only make sure that client always returns the correct data type + $code .= "\$client->return_type = '{$prefix}vals';\n"; + //$code .= "\$client->setDebug(\$debug);\n"; + return $code; +}