ar\connect\xmlrpc

This module provides a simple API to create XML-RPC clients or servers. It is based on Ripcord.

Examples:

Simple RPC client:

<pinp>
$apiKey = 'e3dee9d19a8c3af7c92f9067d2945b59';
$client = ar('connect/xmlrpc')->client('http://www.moviemeter.nl/ws');
$score = $client->film->getScore( $apiKey, 500 );
</pinp>

Simple RPC Server:

<pinp>
$server = ar('connect/xmlrpc')->server( array(
'getName' => 'system.get.name.phtml',
'getTime' => array( 'xmlrpc.get.time', 'timezone' )
) );
$server->run();
</pinp>

methods

(object) base64 This method returns an XML-RPC base64 object from a given binary string.
(string) binary This method returns a (binary) string from a given XML-RPC base64 object.
(object) client This method returns a new XML-RPC client.
(object) datetime This method returns an XML-RPC datetime object from a given unix timestamp.
(object) encodeCall This method creates a new RPC-Call object, which encodes the information needed for a method call to an rpc server. This is mostly used for the system.multiCall method
(array) fault This method generates an XML-RPC fault with the given code and message.
(string) getType This method returns the type of the given parameter.
(bool) isFault This method checks whether the given argument is an XML-RPC fault.
(object) server This method returns a new XML-RPC server.
(int) timestamp This method returns a unix timestamp from a given XML-RPC datetime object.

base64

(object) ar('connect/xmlrpc')->base64( $binary )

(string) $binary The string to convert to XML-RPC base64 type.

Returns an XML-RPC base64 variable converted from the given (binary) string.

binary

(string) ar('connect/xmlrpc')->binary( $base64 )

(object) $base64 The XML-RPC base64 variable to convert to binary string.

This method returns a (binary) string from a given XML-RPC base64 object. It will return an ar_error if the variable is not of the correct type. 

client

(object) ar('connect/xmlrpc')->client( $url, $options = null )

(string) $url The URL of the XML-RPC server to connect to.
(array) $options A list of options to control the generated XML-RPC request.

This method creates a new XML-RPC client connected to the given server URL. Below is a list of valid options:

(string) encoding Character encoding to use. Default is utf-8.
(string) escaping Determines how/whether to escape certain characters. Options are 'cdata', 'non-ascii', 'non-print' and 'markup'. Default is 'markup'.

The client has builtin support for XML-RPC namespaces. A method with the name 'system.listMethods' can be accessed as follows:

<pinp>
$client = ar('connect/xmlrpc')->client( $url );
$result = $client->system->listMethods();
</pinp>

The HTTP response headers can be retrieved through the _responseHeaders property, e.g.:

$headers = $client->_responseHeaders;

datetime

(object) ar('connect/xmlrpc')->datetime( $timestamp )

(int) $timestamp The UNIX timestamp to convert to XML-RPC datetime type.

Returns an XML-RPC datetime variable converted from the UNIX timestamp argument. 

encodeCall

(object) ar('connect/xmlrpc')->encodeCall( $method, $args, ... )

(string) $method The name of the method to call.
(mixed) $args, ... The arguments to pass to the method.

Returns an XML-RPC call object with the method call encoded. This is mostly usefull when calling a 'system.multiCall' method, e.g.:

<pinp>
$xmlrpc = ar('connect/xmlrpc');
$client = $xmlrpc->client( $url );
$result = $client->system->multiCall( array(
    "score" => $xmlrpc->encodeCall( 'film.getScore',
'e3dee9d19a8c3af7c92f9067d2945b59', 500 ), 
    "methods" => $xmlrpc->encodeCall( 'system.listMethods' ) 
  ) ); 
</pinp> 

fault

(array) ar('connect/xmlrpc')->fault( $code, $message )

(int) $code The Fault code.
(string) $message The Fault message.

Returns an XML-RPC Fault array. Any faults in XML-RPC server methods should be returned using this method.

getType

(object) ar('connect/xmlrpc')->getType( $param )

(mixed) $param The parameter from which to get the type.

Returns the type of the given parameter. This can be any of the XML-RPC data types 'struct', 'int', 'string', 'base64', 'boolean', 'double', 'array' or 'datetime'.

isFault

(object) ar('connect/xmlrpc')->isFault( $param )

(mixed) $param The parameter to check.

Returns true if the given parameter is an XML-RPC fault. 

server

(object) ar('connect/xmlrpc')->server( $methods, $options = null )

(array) $methods The list of methods the server implements.
(array) $options A list of options to control the generated XML-RPC request.

This method creates a new XML-RPC server with the given methods. The methods list must be of the form:

array( 'methodName' => 'templateName', ... )

or

array( 'methodName' => array( 'templateName', 'parameterName', ... ), ... ) 

Parameters will be passed by name to the template, according to the order defined above. All methods will be handled by the given template, called on the current object. Below is a list of valid options:

(string) encoding Character encoding to use. Default is utf-8.
(string) escaping Determines how/whether to escape certain characters. Options are 'cdata', 'non-ascii', 'non-print' and 'markup'. Default is 'markup'.

Example:

<pinp>
$server = ar('connect/xmlrpc')->server( array(
'getName' => 'system.get.name.phtml',
'getTime' => array( 'xmlrpc.get.time', 'timezone' )
) );
$server->run();
</pinp>

The server implements the following methods:

(mixed) call Calls a method on the server by its registered name.
(string) handle Calls a method with arguments as encoded in an XML-RPC request and returns the XML-RPC encoded result.
(void) run Gets the XML-RPC request and handles it.
(void) setOutputOption Allows you to set specific outputOptions for the server. See the $options parameter for ar_connect_xmlrpc::server().

(mixed) $xmlrpcServer->call( $method, $args = null )

(string) $method The name of the method to call.
(array) $args The parameters for the method.

This method is mostly usefull for debugging an XML-RPC server. It will call the method by its registered name, but it does no XML-RPC encoding or decoding.

(string) $xmlrpcServer->handle( $request )

(string) $request The request XML.

This method parses the request xml and calls the requested method with the requested parameters. It returns the result encoded as an XML-RPC response.

(void) $xmlrpcServer->run()

This method gathers the request XML sent to the server and handles it. It prints the resulting XML-RPC response. 

timestamp

(int) ar('connect/xmlrpc')->timestamp( $datetime )

(object) $datetime The XML-RPC datetime variable to convert to UNIX timestamp.

This method returns a UNIX timestamp from a given XML-RPC datetime object. It will return an ar_error if the variable is not of the correct type.