cvs: peardoc / global.ent manual.xml.in /en/package webservices.xml /en/package/webservices xml-rpc.xml /en/package/webservices/xml-rpc api.xml
examples.xml intro.xml support.xml

From: Date: Sun, 21 Dec 2003 14:24:40 +0000
Subject: cvs: peardoc / global.ent manual.xml.in /en/package webservices.xml /en/package/webservices xml-rpc.xml /en/package/webservices/xml-rpc api.xml
examples.xml intro.xml support.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-2058@lists.php.net to get a copy of this message
mj Sun Dec 21 09:24:40 2003 EDT Added files: /peardoc/en/package webservices.xml /peardoc/en/package/webservices xml-rpc.xml /peardoc/en/package/webservices/xml-rpc api.xml examples.xml intro.xml support.xml Modified files: /peardoc manual.xml.in global.ent Log: * Initial import of the XML_RPC documentation

Index: peardoc/manual.xml.in diff -u peardoc/manual.xml.in:1.22 peardoc/manual.xml.in:1.23 --- peardoc/manual.xml.in:1.22 Mon Nov 24 14:46:58 2003 +++ peardoc/manual.xml.in Sun Dec 21 09:24:38 2003 @@ -84,6 +84,7 @@ &package.system; &package.text; &package.xml; + &package.webservices; </part> <part id="pecl"> Index: peardoc/global.ent diff -u peardoc/global.ent:1.25 peardoc/global.ent:1.26 --- peardoc/global.ent:1.25 Sun Oct 19 12:19:36 2003 +++ peardoc/global.ent Sun Dec 21 09:24:38 2003 @@ -1,6 +1,6 @@ <!-- -*- SGML -*- - $Id: global.ent,v 1.25 2003/10/19 16:19:36 mj Exp $ + $Id: global.ent,v 1.26 2003/12/21 14:24:38 mj Exp $ Contains global "macros" for all the XML documents. @@ -36,6 +36,7 @@ <!ENTITY url.opl 'http://www.opencontent.org/openpub/'> <!ENTITY url.man.index 'http://unixhelp.ed.ac.uk/alphabetical/index.html'> <!ENTITY url.man.freebsd.index 'http://www.freebsd.org/cgi/man.cgi'> +<!ENTITY url.meerkat 'http://meerkat.oreillynet.com/'> <!ENTITY url.pecl 'http://pecl.php.net/'> <!ENTITY url.phpdoc 'http://www.phpdoc.de/'> <!ENTITY url.phpdocumentor 'http://www.phpdoc.org/'> @@ -66,10 +67,18 @@ <!ENTITY url.rss.info 'http://www.purl.org/rss/'> <!ENTITY url.sourceforge 'http://www.sourceforge.net/'> <!ENTITY url.tabs.vs.spaces 'http://www.jwz.org/doc/tabs-vs-spaces.html'> +<!ENTITY url.usefulinc 'http://usefulinc.com/'> +<!ENTITY url.usefulinc.xmlrpc.doc 'http://xmlrpc.usefulinc.com/doc/'> +<!ENTITY url.userland 'http://www.userland.com/'> <!ENTITY url.xmail 'http://www.phpguru.org/xmail/'> <!ENTITY url.xmlrpc 'http://www.xmlrpc.com/'> +<!ENTITY url.xmlrpc.discuss 'http://www.xmlrpc.com/discuss/'> +<!ENTITY url.xmlrpc.list 'http://groups.yahoo.com/group/xml-rpc/'> +<!ENTITY url.xmlrpc.book 'http://www.oreilly.com/catalog/progxmlrpc/'> +<!ENTITY url.xmlrpc.spec 'http://www.xmlrpc.com/stories/storyReader$7'> <!ENTITY url.extreme.prog 'http://xprogramming.com/'> <!ENTITY url.w3 'http://www.w3.org/'> +<!ENTITY url.w3.xml.rec 'http://www.w3.org/TR/REC-xml#syntax'> <!-- These are special reference/search urls ex. <ulink url="&url.rfc;4242">RFC 4242</ulink> Index: peardoc/en/package/webservices.xml +++ peardoc/en/package/webservices.xml <!-- $Revision: 1.1 $ --> <chapter id="package.webservices"> <title>Web Services</title> <para> </para> &package.webservices.xml-rpc; </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: peardoc/en/package/webservices/xml-rpc.xml +++ peardoc/en/package/webservices/xml-rpc.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.webservices.xml-rpc"> <title>XML_RPC</title> <para> PHP implementation of the XML-RPC protocol. </para> <para> This is a PEAR-ified version of Useful inc's XML-RPC for PHP. It has support for HTTP transport, proxies and authentication. </para> &package.webservices.xml-rpc.intro; &package.webservices.xml-rpc.support; &package.webservices.xml-rpc.examples; &package.webservices.xml-rpc.api; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: peardoc/en/package/webservices/xml-rpc/api.xml +++ peardoc/en/package/webservices/xml-rpc/api.xml <!-- $revision: 1.3 $ --> <refentry id="package.webservices.xml-rpc.api"> <refnamediv> <refname>API</refname> <refpurpose>Class documentation of the package</refpurpose> </refnamediv> <refsect1 id="package.webservices.xml-rpc.api.client"> <title>XML_RPC_Client</title> <para> This is the basic class used to represent a client of an XML-RPC server. </para> <refsect2> <title>Creation</title> <para> The constructor has the following syntax: </para> <funcsynopsis> <funcprototype> <funcdef>$client = new XML_RPC_Client</funcdef> <paramdef><parameter>$server_path</parameter></paramdef> <paramdef><parameter>$server_hostname</parameter></paramdef> <paramdef><parameter>$server_port</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Here's an example client set up to query Userland's XML-RPC server at <emphasis>betty.userland.com</emphasis>: </para> <programlisting role="php"> $client = new XML_RPC_Client("/RPC2", "betty.userland.com", 80); </programlisting> <note> <para> The <parameter>server_port</parameter> parameter is optional, and if omitted will default to 80 when using HTTP and 443 when using HTTPS (see the "send" method below.) </para> </note> </refsect2> <refsect2> <title>Methods</title> <para> This class supports the following methods. </para> <refsect3> <title>send</title> <para> This method takes the form: </para> <funcsynopsis> <funcprototype> <funcdef>$response = $client->send</funcdef> <paramdef><parameter>$xmlrpc_message</parameter></paramdef> <paramdef><parameter>$timeout</parameter></paramdef> <paramdef><parameter>$server_method</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Where <parameter>$xmlrpc_message</parameter> is an instance of <classname>XML_RPC_Message</classname> and <parameter>$response</parameter> is an instance of <classname>XML_RPC_Response</classname> (see <xref linkend="package.webservices.xml-rpc.api.response" />). </para> <para> The <parameter>$timeout</parameter> is optional, and will be set to <literal>0</literal> (wait forever) if omitted. This timeout value is passed to <function>fsockopen</function>. </para> <para> The <parameter>server_method</parameter> parameter is optional, and if omitted will default to 'http'. The only other valid value is 'https', which will use an SSL HTTP connection to connect to the remote server. Note that your PHP must have the "curl" extensions compiled in in order to use this feature. Note that when using SSL you should normally set your port number to 443, unless the SSL server you are contacting runs at any other port. </para> <warning> <para> PHP 4.0.2 or greater is required for SSL functionality. PHP 4.0.6 has a bug which prevents SSL working. </para> </warning> <para> If the value of <parameter>$response</parameter> is <literal>0</literal> rather than an <classname>XML_RPC_Response</classname> object, then this signifies an I/O error has occured. You can find out what the I/O error was from the values <function>$client->errno</function> and <function>$client->errstring</function>. </para> <para> In addition to low-level errors, the XML-RPC server you were querying may return an error in the <classname>XML_RPC_Response</classname> object. See <xref linkend="package.webservices.xml-rpc.api.response" /> for details of how to handle these errors. </para> </refsect3> <refsect3> <title>setCredentials</title> <funcsynopsis> <funcprototype> <funcdef>$client->setCredentials</funcdef> <paramdef><parameter>$username</parameter></paramdef> <paramdef><parameter>$password</parameter></paramdef> </funcprototype> </funcsynopsis> <para> This method sets the username and password for authorizing the client to a server. With the default (HTTP) transport, this information is used for HTTP Basic authorization. </para> </refsect3> <refsect3> <title>setCertificate</title> <funcsynopsis> <funcprototype> <funcdef>$client->setCertificate</funcdef> <paramdef><parameter>$certificate</parameter></paramdef> <paramdef><parameter>$passphrase</parameter></paramdef> </funcprototype> </funcsynopsis> <para> This method sets the optional certificate and passphrase used in SSL-enabled communication with a remote server (when the <parameter>server_method</parameter> is set to 'https' in the client's construction). </para> <para> The <parameter>certificate</parameter> parameter must be the filename of a PEM formatted certificate. The <parameter>passphrase</parameter> parameter must contain the password required to use the certificate. </para> <para> This requires the "curl" extensions to be compiled into your installation of PHP. </para> </refsect3> <refsect3> <title>setSSLVerifyPeer</title> <funcsynopsis> <funcprototype> <funcdef>$client->setSSLVerifyPeer</funcdef> <paramdef><parameter>$i</parameter></paramdef> </funcprototype> </funcsynopsis> <para> This method defines whether connections made to XML-RPC backends via HTTPS should verify the remote host's SSL certificate, and cause the connection to fail if the cert verification fails. $i should be a boolean value. </para> </refsect3> <refsect3> <title>setSSLVerifyHost</title> <funcsynopsis> <funcprototype> <funcdef>$client->setSSLVerifyHost</funcdef> <paramdef><parameter>$i</parameter></paramdef> </funcprototype> </funcsynopsis> <para> This method defines whether connections made to XML-RPC backends via HTTPS should verify the remote host's SSL certificate's common name (CN). By default, only the existence of a CN is checked. $i should be an integer value; 0 to not check the CN at all, 1 to merely check for its existence, and 2 to check that the CN on the certificate matches the hostname that is being connected to. </para> </refsect3> <refsect3> <title>setDebug</title> <funcsynopsis> <funcprototype> <funcdef>$client->setDebug</funcdef> <paramdef><parameter>$debugOn</parameter></paramdef> </funcprototype> </funcsynopsis> <para> <parameter>$debugOn</parameter> is either <literal>0</literal> or <literal>1</literal> depending on whether you require the client to print debugging information to the browser. The default is not to output this information. </para> <para> The debugging information includes the raw data returned from the XML-RPC server it was querying, and the PHP value the client attempts to create to represent the value returned by the server. This option can be very useful when debugging servers as it allows you to see exactly what the server returns. </para> </refsect3> </refsect2> </refsect1> <refsect1 id="package.webservices.xml-rpc.api.message" xreflabel="XML_RPC_Message"> <title>XML_RPC_Message</title> <para> This class provides a representation for a request to an XML-RPC server. A client sends an <classname>XML_RPC_Message</classname> to a server, and receives back an <classname>XML_RPC_Response</classname>. </para> <refsect2> <title>Creation</title> <para> The constructor takes the following form: </para> <funcsynopsis> <funcprototype> <funcdef>$msg = new XML_RPC_Message</funcdef> <paramdef><parameter>$methodName</parameter></paramdef> <paramdef><parameter>$parameterArray</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Where <parameter>$methodName</parameter> is a string indicating the name of the method you wish to invoke, and <parameter>$parameterArray</parameter> is a simple <classname>Array</classname> of <classname>XML_RPC_Value</classname> objects. Here's an example message to the <emphasis>US state name</emphasis> server: </para> <programlisting role="php"> require_once "XML/RPC.php"; $msg = new XML_RPC_Message("examples.getStateName", array(new XML_RPC_Value(23, "int"))); </programlisting> <para> This example requests the name of state number 23. For more information on <classname>XML_RPC_Value</classname> objects, see <xref linkend="package.webservices.xml-rpc.api.value" />. </para> </refsect2> <refsect2> <title>Methods</title> <refsect3> <title>serialize</title> <funcsynopsis> <funcprototype> <funcdef>$outString = $msg->serialize</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns the an XML string representing the XML-RPC message. </para> </refsect3> <refsect3> <title>addParam</title> <funcsynopsis> <funcprototype> <funcdef>$msg->addParam</funcdef> <paramdef><parameter>$xmlrpcVal</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Adds the <classname>XML_RPC_Value</classname> <parameter>$xmlrpcVal</parameter> to the parameter list for this method call. </para> </refsect3> <refsect3> <title>getParam</title> <funcsynopsis> <funcprototype> <funcdef>$xmlrpcVal = $msg->getParam</funcdef> <paramdef><parameter>$n</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Gets the <parameter>$n</parameter>th parameter in the message. Use this method in server implementations. Returns the <literal>undef</literal> value if no such parameter exists. </para> </refsect3> <refsect3> <title>getNumParams</title> <funcsynopsis> <funcprototype> <funcdef>$n = $msg->getNumParams</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns the number of parameters attached to this message. </para> </refsect3> <refsect3> <title>method</title> <funcsynopsis> <funcprototype> <funcdef>$methName=$msg->method</funcdef> <paramdef></paramdef> </funcprototype> <funcprototype> <funcdef>$msg->method</funcdef> <paramdef><parameter>$methName</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Gets or sets the method contained in the XML-RPC message. </para> </refsect3> <refsect3> <title>parseResponse</title> <funcsynopsis> <funcprototype> <funcdef>$response = $msg->parseResponse</funcdef> <paramdef><parameter>$xmlString</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Given an incoming XML-RPC server response contained in the string <parameter>$xmlString</parameter>, this method constructs an <classname>XML_RPC_Response</classname> response object and returns it, setting error codes as appropriate. </para> <para> This method processes any HTTP/MIME headers it finds. </para> </refsect3> <refsect3> <title>parseResponseFile</title> <funcsynopsis> <funcprototype> <funcdef>$response = $msg->parseResponseFile</funcdef> <paramdef><parameter>$fileHandle</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Given an incoming XML-RPC server response on the file handle <parameter>$fileHandle</parameter>, this method reads the data and passes it to <function>parseResponse</function>. </para> <para> This method is useful to construct responses from pre-prepared files. It processes any HTTP headers it finds. </para> </refsect3> </refsect2> </refsect1> <refsect1 id="package.webservices.xml-rpc.api.response" xreflabel="XML_RPC_Response"> <title>XML_RPC_Response</title> <para> This class is used to contain responses to XML-RPC requests. A server method handler will construct an <classname>XML_RPC_Response</classname> and pass it as a return value. This same value will be returned by the result of an invocation of the <function>send</function> method of the <classname>XML_RPC_Client</classname> class. </para> <refsect2> <title>Creation</title> <funcsynopsis> <funcprototype> <funcdef>$resp = new XML_RPC_Response</funcdef> <paramdef><parameter>$xmlrpcval</parameter></paramdef> </funcprototype> <funcprototype> <funcdef>$resp = new XML_RPC_Response</funcdef> <paramdef><parameter>0</parameter></paramdef> <paramdef><parameter>$errcode</parameter></paramdef> <paramdef><parameter>$errstring</parameter></paramdef> </funcprototype> </funcsynopsis> <para> The first instance is used when execution has happened without difficulty: <parameter>$xmlrpcval</parameter> is an <classname>XML_RPC_Value</classname> value with the result of the method execution contained in it. </para> <para> The second type of constructor is used in case of failure. <parameter>$errcode</parameter> and <parameter>$errstring</parameter> are used to provide indication of what has gone wrong. See <xref linkend="package.webservices.xml-rpc.api.server" /> for more information on passing error codes. </para> </refsect2> <refsect2> <title>Methods</title> <refsect3> <title>faultCode</title> <funcsynopsis> <funcprototype> <funcdef>$fn = $resp->faultCode</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns the integer fault code return from the XML-RPC response <parameter>$resp</parameter>. A zero value indicates success, any other value indicates a failure response. </para> </refsect3> <refsect3> <title>faultString</title> <funcsynopsis> <funcprototype> <funcdef>$fs = $resp->faultString</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns the human readable explanation of the fault indicated by <function>$resp->faultCode</function>. </para> </refsect3> <refsect3> <title>value</title> <funcsynopsis> <funcprototype> <funcdef>$xmlrpcVal = $resp->value</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns an <classname>XML_RPC_Value</classname> object containing the return value sent by the server. If the response's <function>faultCode</function> is non-zero then the value returned by this method should not be used (it may not even be an object). </para> </refsect3> <refsect3> <title>serialize</title><para></para> <funcsynopsis> <funcprototype> <funcdef>$outString = $resp->serialize</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns an XML string representation of the response. </para> </refsect3> </refsect2> </refsect1> <refsect1 id="package.webservices.xml-rpc.api.value" xreflabel="XML_RPC_Value"> <title>XML_RPC_Value</title> <para> This is where a lot of the hard work gets done. This class enables the creation and encapsulation of values for XML-RPC. </para> <para> Ensure you've read the XML-RPC spec at <ulink url="&url.xmlrpc.spec;">&url.xmlrpc.spec;</ulink> before reading on as it will make things clearer. </para> <para> The <classname>XML_RPC_Value</classname> class can store arbitrarily complicated values using the following types: <literal>i4 int boolean string double dateTime.iso8601 base64 array struct</literal>. You should refer to the <ulink url="&url.xmlrpc.spec;">spec</ulink> for more information on what each of these types mean. </para> <refsect2> <title>Notes on types</title> <refsect3> <title>int</title> <para> The type <classname>i4</classname> is accepted as a synonym for <classname>int</classname>. The value parsing code will always convert <classname>i4</classname> to <classname>int</classname>: <classname>int</classname> is regarded by this implementation as the canonical name for this type. </para> </refsect3> <refsect3> <title>base64</title> <para> Base 64 encoding is performed transparently to the caller when using this type. Therefore you ought to consider it as a "binary" data type, for use when you want to pass none 7-bit clean data. Decoding is also transparent. </para> </refsect3> <refsect3> <title>boolean</title> <para> The values <literal>true</literal> and <literal>1</literal> map to <literal>true</literal>. All other values (including the empty string) are converted to <literal>false</literal>. </para> </refsect3> <refsect3> <title>string</title> <para> The characters <literal>&lt; &gt; &quot;</literal> and <literal>&amp;</literal> are converted to their entity equivalents <literal>&amp;lt; &amp;gt; &amp;quot;</literal> and <literal>&amp;amp;</literal> for transport through XML-RPC. The current XML-RPC spec recommends only encoding <literal>&lt; &amp;</literal> but this implementation goes further, for reasons explained by <ulink url="&url.w3.xml.rec;">the XML 1.0 recommendation</ulink>. </para> <para> TODO: <literal> &amp;apos;</literal> entity not yet supported </para> </refsect3> </refsect2> <refsect2 id="package.webservices.xml-rpc.api.value.creation" xreflabel="XML_RPC_Value constructors"> <title>Creation</title> <para> The constructor is the normal way to create an <classname>XML_RPC_Value</classname>. The constructor can take these forms: </para> <funcsynopsis> <funcprototype> <funcdef>$myVal = new XML_RPC_Value</funcdef> <paramdef></paramdef> </funcprototype> <funcprototype> <funcdef>$myVal = new XML_RPC_Value</funcdef> <paramdef><parameter>$stringVal</parameter></paramdef> </funcprototype> <funcprototype> <funcdef>$myVal = new XML_RPC_Value</funcdef> <paramdef><parameter>$scalarVal</parameter></paramdef> <paramdef><parameter>"int" | "boolean" | "string" | "double" | "dateTime.iso8601" | "base64"</parameter></paramdef> </funcprototype> <funcprototype> <funcdef>$myVal = new XML_RPC_Value</funcdef> <paramdef><parameter>$arrayVal</parameter></paramdef> <paramdef><parameter>"array" | "struct"</parameter></paramdef> </funcprototype> </funcsynopsis> <para> The first constructor creates an empty value, which must be altered using the methods <function>addScalar</function>, <function>addArray</function> or <function>addStruct</function> before it can be used. </para> <para> The second constructor creates a simple string value. </para> <para> The third constructor is used to create a scalar value. The second parameter must be a name of an XML-RPC type. Examples: </para> <programlisting role="php"> $myInt = new XML_RPC_Value(1267, "int"); $myString= new XML_RPC_Value("Hello, World!", "string"); $myBool = new XML_RPC_Value(1, "boolean"); </programlisting> <para> The fourth constructor form can be used to compose complex XML-RPC values. The first argument is either a simple array in the case of an XML-RPC <classname>array</classname> or an associative array in the case of a <classname>struct</classname>. The elements of the array <emphasis>must be <classname>XML_RPC_Value</classname> objects themselves</emphasis>. Examples: </para> <programlisting> $myArray = new XML_RPC_Value(array( new XML_RPC_Value("Tom"), new XML_RPC_Value("Dick"), new XML_RPC_Value("Harry")), "array"); $myStruct = new XML_RPC_Value(array( "name" => new XML_RPC_Value("Tom"), "age" => new XML_RPC_Value(34, "int"), "geek" => new XML_RPC_Value(1, "boolean")), "struct"); </programlisting> </refsect2> <refsect2 id="package.webservices.xml-rpc.api.value.methods" xreflabel="XML_RPC_Value methods"> <title>Methods</title> <refsect3> <title>addScalar</title> <funcsynopsis> <funcprototype> <funcdef>$ok = $val->addScalar</funcdef> <paramdef><parameter>$stringVal</parameter></paramdef> </funcprototype> <funcprototype> <funcdef>$ok = $val->addScalar</funcdef> <paramdef><parameter>$scalarVal</parameter></paramdef> <paramdef><parameter>"int" | "boolean" | "string" | "double" | "dateTime.iso8601" | "base64"</parameter></paramdef> </funcprototype> </funcsynopsis> <para> If <parameter>$val</parameter> is an empty <classname>XML_RPC_Value</classname> this method makes it a scalar value, and sets that value. If <parameter>$val</parameter> is already a scalar value, then no more scalars can be added and <literal>0</literal> is returned. If all went OK, <literal>1</literal> is returned. </para> <para> There is a special case if <parameter>$val</parameter> is an <classname>array</classname>: the scalar value passedis appended to the array. </para> </refsect3> <refsect3> <title>addArray</title> <funcsynopsis> <funcprototype> <funcdef>$ok = $val->addArray</funcdef> <paramdef><parameter>$arrayVal</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Turns an empty <classname>XML_RPC_Value</classname> into an <classname>array</classname> with contents as specified by <parameter>$arrayVal</parameter>. See the fourth constructor form for more information. </para> </refsect3> <refsect3> <title>addStruct</title> <funcsynopsis> <funcprototype> <funcdef>$ok = $val->addArray</funcdef> <paramdef><parameter>$assocArrayVal</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Turns an empty <classname>XML_RPC_Value</classname> into a <classname>struct</classname> with contents as specified by <parameter>$assocArrayVal</parameter>. See the fourth constructor form for more information. </para> </refsect3> <refsect3> <title>kindOf</title> <funcsynopsis> <funcprototype> <funcdef>$kind = $val->kindOf</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns a string containing "struct", "array" or "scalar" describing the base type of the value. If it returns "undef" it means that the value hasn't been initialised. </para> </refsect3> <refsect3> <title>serialize</title> <funcsynopsis> <funcprototype> <funcdef>$outString = $val->serialize</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns a string containing the XML-RPC representation of this value. </para> </refsect3> <refsect3> <title>scalarval</title> <funcsynopsis> <funcprototype> <funcdef>$scalarVal = $val->scalarval</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> If <function>$val->kindOf() == "scalar"</function>, this method returns the actual PHP-language value of the scalar (base 64 decoding is automatically handled here). </para> </refsect3> <refsect3> <title>scalartyp</title> <funcsynopsis> <funcprototype> <funcdef>$typeName = $val->scalartyp</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> If <function>$val->kindOf() == "scalar"</function>, this method returns a string denoting the type of the scalar. As mentioned before, <literal>i4</literal> is always coerced to <literal>int</literal>. </para> </refsect3> <refsect3> <title>arraymem</title> <funcsynopsis> <funcprototype> <funcdef>$xmlrpcVal = $val->arraymem</funcdef> <paramdef><parameter>$n</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Returns the <parameter>$n</parameter>th element in the array represented by the value <parameter>$val</parameter>. The value returned is an <classname>XML_RPC_Value</classname> object. </para> </refsect3> <refsect3> <title>arraysize</title> <funcsynopsis> <funcprototype> <funcdef>$len = $val->arraysize</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> If <parameter>$val</parameter> is an <classname>array</classname>, returns the number of elements in that array. </para> </refsect3> <refsect3> <title>structmem</title> <funcsynopsis> <funcprototype> <funcdef>$xmlrpcVal = $val->structmem</funcdef> <paramdef><parameter>$memberName</parameter></paramdef> </funcprototype> </funcsynopsis> <para> Returns the element called <parameter>$memberName</parameter> from the struct represented by the value <parameter>$val</parameter>. The value returned is an <classname>XML_RPC_Value</classname> object. </para> </refsect3> <refsect3> <title>structeach</title> <funcsynopsis> <funcprototype> <funcdef>list($key,$value) = $val->structeach</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Returns the next (key,value) pair from the struct, when <parameter>$val</parameter> is a struct. See also <xref linkend="package.webservices.xml-rpc.api.value.methods.structreset" />. </para> </refsect3> <refsect3 id="package.webservices.xml-rpc.api.value.methods.structreset" xreflabel="structreset()"> <title>structreset</title> <funcsynopsis> <funcprototype> <funcdef>$val->structreset</funcdef> <paramdef></paramdef> </funcprototype> </funcsynopsis> <para> Resets the internal pointer for <function>structeach()</function> to the beginning of the struct, where <parameter>$val</parameter> is a struct. </para> </refsect3> </refsect2> </refsect1> <refsect1 id="package.webservices.xml-rpc.api.server" xreflabel="XML_RPC_Server"> <title>XML_RPC_Server</title> <para> The current implementation of this class has been kept as simple as possible. The constructor for the server basically does all the work. Here's a minimal example: </para> <programlisting role="php"> function foo ($params) { ... } $s = new XML_RPC_Server(array("examples.myFunc" => array("function" => "foo"))); </programlisting> <para> This performs everything you need to do with a server. The single argument is an associative array from method names to function names. The request is parsed and despatched to the relevant function, which is reponsible for returning a <classname>XML_RPC_Response</classname> object, which gets serialized back to the caller. </para> <para> Here is a more detailed look at what the handler function <function>foo</function> may do: </para> <programlisting role="php"> function foo ($params) { global $xmlrpcerruser; // import user errcode value // $params is an Array of XML_RPC_Value objects if ($err) { // this is an error condition return new XML_RPC_Response(0, $xmlrpcerruser+1, // user error 1 "There's a problem, Captain"); } else { // this is a successful value being returned return new XML_RPC_Response(new XML_RPC_Value("All's fine!", "string")); } } </programlisting> <refsect2> <title>The dispatch map</title> <para> The first argument to the <function>XML_RPC_Server</function> constructor is an array, called the <emphasis>dispatch map</emphasis>. In this array is the information the server needs to service the XML-RPC methods you define. </para> <para> The dispatch map takes the form of an associative array of associative arrays: the outer array has one entry for each method, the key being the method name. The corresponding value is another associative array, which can have the following members: </para> <itemizedlist> <listitem> <para> <function>function</function> - this entry is mandatory. It must be a name of a function in the global scope which services the XML-RPC method. </para> </listitem> <listitem> <para> <function>signature</function> - this entry is an array containg the possible signatures (see <xref linkend="package.webservices.xml-rpc.api.server.signatures" />) for the method. If this entry is present then the server will check that the correct number and type of parameters have been sent for this method before dispatching it. </para> </listitem> <listitem> <para> <function>docstring</function> - this entry is a string containing documentation for the method. The documentation may contain HTML markup. </para> </listitem> </itemizedlist> </refsect2> <refsect2 id="package.webservices.xml-rpc.api.server.signatures" xreflabel="Signatures"> <title>Method signatures</title> <para> A signature is a description of a method's return type and its parameter types. A method may have more than one signature. </para> <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 <programlisting role="php"> string examples.getStateName(int)</programlisting> has the signature <programlisting role="php">array($xmlrpcString, $xmlrpcInt)</programlisting> and, assuming that it the only possible signature for the method, might be used like this in server creation: </para> <programlisting role="php"> $findstate_sig = array(array($xmlrpcString, $xmlrpcInt)); $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" =&gt; array("function" =&gt; "findstate", "signature" =&gt; $findstate_sig, "docstring" =&gt; $findstate_doc))); </programlisting> <para> For convenience the strings representing the XML-RPC types have been encoded as global variables: </para> <programlisting role="php"> $xmlrpcI4 = "i4"; $xmlrpcInt = "int"; $xmlrpcBoolean = "boolean"; $xmlrpcDouble = "double"; $xmlrpcString = "string"; $xmlrpcDateTime = "dateTime.iso8601"; $xmlrpcBase64 = "base64"; $xmlrpcArray = "array"; $xmlrpcStruct = "struct"; </programlisting> </refsect2> <refsect2> <title>Delaying the server response</title> <para> You may want to construct the server, but for some reason not fulfill the request immediately (security verification, for instance). If you pass the constructor a second argument of <literal>0</literal> this will have the desired effect. You can then use the <function>service()</function> method of the server class to service the request. For example: </para> <programlisting role="php"> $s = new XML_RPC_Server($myDispMap, 0); // ... some code that does other stuff here $s->service(); </programlisting> </refsect2> <refsect2> <title>Fault reporting</title> <para> Fault codes for your servers should start at the value indicated by the global <literal>$xmlrpcerruser</literal> + 1. </para> <para> Standard errors returned by the server include: </para> <variablelist> <varlistentry> <term> <literal>1</literal> <phrase>Unknown method</phrase> </term> <listitem> <para> Returned if the server was asked to dispatch a method it didn't know about </para> </listitem> </varlistentry> <varlistentry> <term> <literal>2</literal> <phrase>Invalid return payload</phrase> </term> <listitem> <para> This error is actually generated by the client, not server, code, but signifies that a server returned something it couldn't understand. </para> </listitem> </varlistentry> <varlistentry> <term> <literal>3</literal> <phrase>Incorrect parameters</phrase> </term> <listitem> <para> This error is generated when the server has signature(s) defined for a method, and the parameters passed by the client do not match any of signatures. </para> </listitem> </varlistentry> <varlistentry> <term> <literal>4</literal> <phrase>Can't introspect: method unknown</phrase> </term> <listitem> <para> This error is generated by the builtin <function>system.*</function> methods when any kind of introspection is attempted on a method undefined by the server. </para> </listitem> </varlistentry> <varlistentry> <term> <literal>5</literal> <phrase>Didn't receive 200 OK from remote server</phrase> </term> <listitem> <para> This error is generated by the client when a remote server doesn't return HTTP/1.1 200 OK in response to a request. A more detailed error report is added onto the end of the phrase above. </para> </listitem> </varlistentry> <varlistentry> <term> <literal>100-</literal> <phrase>XML parse errors</phrase> </term> <listitem> <para> Returns 100 plus the XML parser error code for the fault that occurred. The <function>faultString</function> returned explains where the parse error was in the incoming XML stream. </para> </listitem> </varlistentry> </variablelist> </refsect2> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: peardoc/en/package/webservices/xml-rpc/examples.xml +++ peardoc/en/package/webservices/xml-rpc/examples.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.xml-rpc.examples"> <refnamediv> <refname>Examples</refname> <refpurpose>Usage examples for the XML_RPC package</refpurpose> </refnamediv> <refsect1 id="package.webservices.xml-rpc.examples.statename"> <title>XML-RPC client: state name query</title> <para> Code to get the corresponding state name from a number (1-50) from Dave Winer's server. </para> <programlisting role="php"> <![CDATA[ require_once "XML/RPC.php"; /** * Get the name of state 42 (Tenesse) */ $params = array(new XML_RPC_Value(42, "int")); $msg = new XML_RPC_Message("examples.getStateName", $params); $client = new XML_RPC_Client("/RPC2", "betty.userland.com", 80); $response = $client->send($msg); $v = $response->value(); if (!$response->faultCode()) { print "State number 42 is " . $v->scalarval() . "\n"; print "I got this value back:\n" . $response->serialize() . "\n"; } else { print "Fault: "; print "Code: " . $response->faultCode() . " Reason '" . $response->faultString() . "'\n"; } ]]> </programlisting> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: peardoc/en/package/webservices/xml-rpc/intro.xml +++ peardoc/en/package/webservices/xml-rpc/intro.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.xml-rpc.intro"> <refnamediv> <refname>Introduction</refname> <refpurpose></refpurpose> </refnamediv> <refsect1 id="package.webservices.xml-rpc.intro.general"> <title>General introduction</title> <para> XML-RPC is a format devised by <ulink url="&url.userland;">Userland Software</ulink> for achieving remote procedure call via XML. XML-RPC has its own web site, <ulink url="&url.xmlrpc;">www.XmlRpc.com</ulink>. </para> <para> The most common implementations of XML-RPC available at the moment use HTTP as the transport. A list of implementations for other languages such as Perl and Python can be found on the <ulink url="&url.xmlrpc;">www.xmlrpc.com</ulink>. </para> <para> This collection of PHP classes provides a framework for writing XML-RPC clients and servers in PHP. </para> </refsect1> <refsect1 id="package.webservices.xml-rpc.intro.acknowledgements"> <title>Acknowledgements</title> <para> This package has been orginially written by <ulink url="&url.usefulinc;">Edd Dumbill</ulink> of Useful Information Company, so he deservers most of the credits. Apart from that following people have contributed to the initial codebase that is still being maintained by Edd: </para> <itemizedlist> <listitem> <para>Jim Winstead <email>jimw at php dot net</email></para> </listitem> <listitem> <para>Peter Kocks <email>peter.kocks at baygate dot com</email></para> </listitem> <listitem> <para>Nicolay Mausz <email>mausz at flying-dog dot com</email></para> </listitem> <listitem> <para>Ben Margolin <email>ben at wendy.auctionwatch dot com</email></para> </listitem> <listitem> <para>Dan Libby <email>dan at libby dot com</email></para> </listitem> <listitem> <para>Gaetano Giunta <email>g.giunta at libero dot it</email></para> </listitem> <listitem> <para>Idan Sofer <email>i_sofer at yahoo dot com</email></para> </listitem> <listitem> <para>Giancarlo Pinerolo <email>ping at alt dot it</email></para> </listitem> <listitem> <para>Justin Miller <email>justin at voxel dot net</email></para> </listitem> </itemizedlist> </refsect1> <refsect1 id="package.webservices.xml-rpc.intro.manifest"> <title>Manifest - Files in the package</title> <titleabbrev>Manifest</titleabbrev> <glosslist> <glossentry> <glossterm>Server.php</glossterm> <glossdef> <para> the XML-RPC server class. <function>include</function> this to get server functionality. </para> </glossdef> </glossentry> <glossentry> <glossterm>RPC.php</glossterm> <glossdef> <para> the XML-RPC client classes. <function>include</function> this to get client functionality. </para> </glossdef> </glossentry> </glosslist> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: peardoc/en/package/webservices/xml-rpc/support.xml +++ peardoc/en/package/webservices/xml-rpc/support.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.xml-rpc.support"> <refnamediv> <refname>Support</refname> <refpurpose>Getting support for XML_RPC</refpurpose> </refnamediv> <refsect1 id="package.webservices.xml-rpc.support.online"> <title>Online Support</title> <para> The package is offered <quote>as-is</quote> without any warranty or commitment to support. However, informal advice and help is available via the PEAR user mailing list and XML-RPC.com. </para> <itemizedlist> <listitem> <para> The <ulink url="mailto:&email.pear.general;">PEAR user mailing list</ulink> can be contacted for questions concerning the usage of the package. More details <ulink url="&url.pear.support;">can be found here</ulink>. </para> </listitem> <listitem> <para> For more general XML-RPC questions, there is a Yahoo! Groups <ulink url="&url.xmlrpc.list;">XML-RPC mailing list</ulink>. </para> </listitem> <listitem> <para>The <ulink url="&url.xmlrpc.discuss;">XML-RPC.com</ulink> discussion group is a useful place to get help with using XML-RPC. This group is also gatewayed into the Yahoo! Groups mailing list.</para> </listitem> </itemizedlist> </refsect1> <refsect1 id="package.webservices.xml-rpc.support.jellyfish"> <title>The Jellyfish Book</title> <para> <graphic fileref="http://www.oreilly.com/catalog/covers/progxmlrpc.s.gif" format="GIF" width="145" depth="190" align="right"></graphic> Together with Simon St.Laurent and Joe Johnston, Edd Dumbill wrote a book on XML-RPC for O'Reilly and Associates on XML-RPC. It features a rather fetching jellyfish on the cover. </para> <para> Complete details of the book are <ulink url="&url.xmlrpc.book;">available from O'Reilly's web site.</ulink> </para> <para> Edd is responsible for the chapter on PHP, which includes a worked example of creating a forum server, and hooking it up the O'Reilly's <ulink url="&url.meerkat;">Meerkat</ulink> service in order to allow commenting on news stories from around the Web. </para> <para> If you've benefitted from the effort he has put into writing this software, then please consider buying the book! </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#2058) next »