cvs: peardoc /en/package/webservices/xml-rpc api.xml
| From: | Daniel Convissor | Date: | Sat, 07 May 2005 23:49:56 +0000 |
| Subject: | cvs: peardoc /en/package/webservices/xml-rpc api.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-5991@lists.php.net to get a copy of this message | ||
danielc Sat May 7 19:49:56 2005 EDT
Modified files:
/peardoc/en/package/webservices/xml-rpc api.xml
Log:
* Improve signature documentation.
http://cvs.php.net/diff.php/peardoc/en/package/webservices/xml-rpc/api.xml?r1=1.12&r2=1.13&ty=u
Index: peardoc/en/package/webservices/xml-rpc/api.xml
diff -u peardoc/en/package/webservices/xml-rpc/api.xml:1.12
peardoc/en/package/webservices/xml-rpc/api.xml:1.13
--- peardoc/en/package/webservices/xml-rpc/api.xml:1.12 Wed Apr 6 11:53:43 2005
+++ peardoc/en/package/webservices/xml-rpc/api.xml Sat May 7 19:49:55 2005
@@ -1079,41 +1079,103 @@
<para>
Within a server's dispatch map, each method has an array of possible
signatures. Each signature is an array of types. The first entry is
- the return type. For instance, the method
+ the return type.
+ </para>
+
+ <para>
+ Let's run through an example. Imagine you wanted to write a
+ regular PHP like this:
<programlisting role="php">
<![CDATA[
-string examples.getStateName(int)
+function is_8($input, $strict = false) {
+ if ($strict) {
+ return ($input === 8);
+ } else {
+ return ($input == 8);
+ }
+}
]]>
</programlisting>
- has the signature
+ </para>
+
+ <para>
+ To get it to work in an XML_RPC server, you would have to
+ write it like this:
<programlisting role="php">
<![CDATA[
-array($xmlrpcString, $xmlrpcInt)
+function is_8($params) {
+ // This parameter is required.
+ $param = $params->getParam(0);
+ if (!XML_RPC_Value::isValue($param)) {
+ return $param;
+ }
+ $input = $param->scalarval();
+
+ // This parameter is optional.
+ $param = $params->getParam(1);
+ if (!XML_RPC_Value::isValue($param)) {
+ $strict = false;
+ } else {
+ $strict = $param->scalarval();
+ }
+
+ if ($strict) {
+ $answer = ($input === 8);
+ } else {
+ $answer = ($input == 8);
+ }
+
+ $val = new XML_RPC_Value($answer, 'boolean');
+ return new XML_RPC_Response($val);
+}
]]>
</programlisting>
- and, assuming that it the only possible
- signature for the method, might be used like this in server
- creation:
</para>
- <programlisting role="php">
- <![CDATA[
-$findstate_sig = array(array($xmlrpcString, $xmlrpcInt));
+ <para>
+ Here is a signature covering all of the
+ possible permutations:
+ <programlisting role="php">
+<![CDATA[
+array(
+ array('boolean', 'int'),
+ array('boolean', 'int', 'boolean'),
+ array('boolean', 'string'),
+ array('boolean', 'string', 'boolean'),
+)
+]]>
+ </programlisting>
+ </para>
-$findstate_doc='When passed an integer between 1 and 51 returns the
- name of a US state, where the integer is the index of that state name
- in an alphabetic order.';
-
-$s = new XML_RPC_Server(array("examples.getStateName" =>
- array("function" => "findstate",
- "signature" => $findstate_sig,
- "docstring" => $findstate_doc)));
- ]]>
- </programlisting>
+ <para>
+ The server could be instatiated like this:
+ <programlisting role="php">
+<![CDATA[
+$server = new XML_RPC_Server(
+ array(
+ 'rpcnameisan8' =>
+ array(
+ 'function' => 'is_8',
+ 'signature' =>
+ array(
+ array('boolean', 'int'),
+ array('boolean', 'int', 'boolean'),
+ array('boolean', 'string'),
+ array('boolean', 'string', 'boolean'),
+ ),
+ 'docstring' => 'Is the value an 8?'
+ ),
+ ),
+ 1,
+ 0
+);
+]]>
+ </programlisting>
+ </para>
<para>
- For convenience the strings representing the XML-RPC types have been
- encoded as global variables:
+ The strings representing the XML-RPC types have been
+ encoded as global variables for your convenience:
</para>
<programlisting role="php">
<![CDATA[