cvs: peardoc /en/package/webservices/xml-rpc2 client.xml
| From: | Fabien MARTY | Date: | Thu, 16 Feb 2006 20:06:26 +0000 |
| Subject: | cvs: peardoc /en/package/webservices/xml-rpc2 client.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-7537@lists.php.net to get a copy of this message | ||
fab Thu Feb 16 20:06:26 2006 UTC
Modified files:
/peardoc/en/package/webservices/xml-rpc2 client.xml
Log:
end of the client howto
http://cvs.php.net/viewcvs.cgi/peardoc/en/package/webservices/xml-rpc2/client.xml?r1=1.2&r2=1.3&diff_format=u
Index: peardoc/en/package/webservices/xml-rpc2/client.xml
diff -u peardoc/en/package/webservices/xml-rpc2/client.xml:1.2
peardoc/en/package/webservices/xml-rpc2/client.xml:1.3
--- peardoc/en/package/webservices/xml-rpc2/client.xml:1.2 Mon Feb 13 23:16:08 2006
+++ peardoc/en/package/webservices/xml-rpc2/client.xml Thu Feb 16 20:06:25 2006
@@ -1,4 +1,4 @@
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<refentry id="package.webservices.xml-rpc2.client">
<refnamediv>
@@ -130,6 +130,101 @@
TO BE CONTINUED
</para>
</refsect1>
+ <refsect1 id="package.webservices.xml-rpc2.client.create">
+ <title>Making the XML_RPC2_Client object</title>
+ <para>
+ It's really easy to make the XML_RPC2_Client object. Use the following syntax :
+ <programlisting role="php">
+ <![CDATA[
+// $XMLRPCServerURL is a string : 'http://pear.php.net/xmlrpc.php' (for example)
+// $options is an optional array : see previous section for more informations
+$client = XML_RPC2_Client::create($XMLRPCServerURL, $options);
+ ]]>
+ </programlisting>
+ Don't try to call the XML_RPC2_Client constructor directly, use the call() static method.
+ </para>
+ </refsect1>
+ <refsect1 id="package.webservices.xml-rpc2.client.call">
+ <title>Call the XMLRPC exported method</title>
+ <para>
+ When the XML_RPC2_Client object is created, you can directly call the remote method as
+ it was local. For example :
+ <programlisting role="php">
+ <![CDATA[
+// We call the remote foo() method without any arguments
+$result1 = $client->foo();
+
+// We call the remote bar() method with two arguments (an integer : 123, a string :
'foo')
+$result2 = $client->bar(123, 'foo');
+
+// We call the remote foobar() method with complex data types (2 integer, a string, a structure)
+$result3 = $client->foobar(1, 2, 'foo', array('foo' => 1, 'bar'
=> 2));
+ ]]>
+ </programlisting>
+ </para>
+ <para>
+ Be carefull, XMLRPC spec allows some remote method names with some special characters like
"." or "/"... which are
+ not available as PHP method names. To deal with them, you have to fix a prefix in a the options
array. For example :
+ <programlisting role="php">
+ <![CDATA[
+$options = array('prefix' => 'foo.');
+$client = XML_RPC2_Client::create('http://...',
$options);
+
+// We call the foo.bar() method because of the prefix 'foo.' fixed in $options array
+$result = $client->bar();
+ ]]>
+ </programlisting>
+ </para>
+ <para>
+ In most cases, XML_RPC2 transforms automatically PHP native types into XMLRPC
+ types (as described in the SPEC) for the request. In most cases too, XML_RPC2
+ transforms the XML server response into PHP native types too. Yet, there are
+ two exceptions : 'dateTime.iso8601' and 'base64' which doesn't really
exist in PHP.
+ </para>
+ <para>
+ To manipulate explicitely these two types, you have to use special objects. Let's see a
+ complete example :
+ <programlisting role="php">
+ <![CDATA[
+<?php
+
+// Classic usage
+require_once 'XML/RPC2/Client.php';
+
+// To manipulate these types, we need to include this file too
+require_once 'XML/RPC2/Value.php';
+
+// To get a 'dateTime.iso8601' object, you have first to set a string with an iso8601
encoded date :
+$tmp = "20060116T19:14:03";
+
+// Then, you call this static method to get your 'dateTime.iso8601' object
+$time = XML_RPC2_Value::createFromNative($tmp, 'datetime');
+
+// For 'base64', you call the same static method with your string to get a
'base64' object
+$base64 = XML_RPC2_Value::createFromNative('foobar', 'base64');
+
+// Then, you can use XML_RPC2_Client as usal :
+$options = array('prefix' => 'validator1.');
+$client = XML_RPC2_Client::create('http://phpxmlrpc.sourceforge.net/server.php',
$options);
+$result = $client->manyTypesTest(1, true, 'foo', 3.14159, $time, $base64);
+
+// The remote validator1.manyTypesTest() method returns an array with the 6 given arguments
+$result_datetime = $result[4]; // a 'dateTime.iso8601' object
+$result_base64 = $result[5]; // a 'base64' object
+
+// To transform these objects into PHP native types, you have to use public properties of
+// these objects as follow :
+var_dump($result_datetime->scalar); // will return string(17) "20060116T19:14:03"
+var_dump($result_datetime->xmlrpc_type); // will return string(8) "datetime"
+var_dump($result_datetime->timestamp); // will return int(1137435243)
+var_dump($result_base64->scalar); // will return string(6) "foobar"
+var_dump($result_base64->xmlrpc_type); // will return string(6) "base64"
+
+?>
+ ]]>
+ </programlisting>
+ </para>
+ </refsect1>
</refentry>
<!-- Keep this comment at the end of the file