XRL  latest
Simple XML-RPC Library (both client and server)
fpoirotte\XRL\Client Class Reference

A simple XML-RPC client. More...

Public Member Functions

 __call ($method, array $args)
 
 __construct ($baseURL,\fpoirotte\XRL\EncoderInterface $encoder=null,\fpoirotte\XRL\DecoderInterface $decoder=null, array $options=array())
 

Protected Attributes

 $baseURL
 The remote XML-RPC server's base URL.
 
 $context
 A stream context to use when querying the server.
 
 $decoder
 Decoder for the response.
 
 $encoder
 Encoder for the request.
 

Detailed Description

A simple XML-RPC client.

To call a remote XML procedure, create a new instance of this class (pass the server's URL to the constructor) and then simply call the procedure as if it was a method of the object returned:

$client = new \\fpoirotte\\XRL\\Client("http://xmlrpc.example.com/");
// This calls the remote procedure "foo"
// and prints the result of that call.
var_dump($client->foo(42));

In case the remote procedure's name is not a valid PHP identifier, you may still call it using the curly braces notation:

// Calls the remote procedure named "foo.bar.baz".
$client->{"foo.bar.baz"}(42);
See also
The example in client.php contains a complete example of a working XML-RPC client for use with XRL's example server (server.php).
Authors
François Poirotte click.nosp@m.y@er.nosp@m.ebot..nosp@m.net

Definition at line 47 of file Client.php.

Constructor & Destructor Documentation

fpoirotte\XRL\Client::__construct (   $baseURL,
\fpoirotte\XRL\EncoderInterface  $encoder = null,
\fpoirotte\XRL\DecoderInterface  $decoder = null,
array  $options = array() 
)

Create a new XML-RPC client.

Parameters
string$baseURLBase URL for the XML-RPC server, eg. "http://www.example.com/xmlrpc/".
fpoirotte::XRL::EncoderInterface$encoder(optional) Encoder to use for requests. If omitted, an encoder that accepts native PHP types, does not use indentation, but uses the <string> tags is automatically created using the machine's timezone.
fpoirotte::XRL::DecoderInterface$decoder(optional) Decoder to use for responses. If omitted, a decoder that performs XML validation and converts values to native PHP types is automatically created using the machine's timezone.
array$options(optional) Options to pass to the stream context when querying the remote XML-RPC server.
Note
See http://php.net/manual/en/timezones.php for a list of valid timezone names supported by PHP.
See http://php.net/manual/en/stream.contexts.php for more information about PHP stream contexts.
Exceptions
InvalidArgumentExceptionThe given timezone or context is invalid.

Definition at line 95 of file Client.php.

References fpoirotte\XRL\Client\$baseURL, fpoirotte\XRL\Client\$decoder, and fpoirotte\XRL\Client\$encoder.

Member Function Documentation

fpoirotte\XRL\Client::__call (   $method,
array  $args 
)

A magic method that forwards all method calls to the remote XML-RPC server and returns that server's response on success or throws an exception on failure.

Parameters
string$methodThe remote procedure to call.
array$argsA list of arguments to pass to the remote procedure.
Return values
mixedThe remote server's response, as a native type (string, int, boolean, float or DateTime object).
Exceptions
fpoirotte::XRL::ExceptionRaised in case the remote server's response indicates some kind of error. You may use this exception's getCode() and getMessage() methods to find out more about the error.
RuntimeExceptionRaised when this client wasn't able to query the remote server (such as when no connection could be established to it).

Definition at line 148 of file Client.php.

References fpoirotte\XRL\Client\$context, and fpoirotte\XRL\CLI\getVersion().


The documentation for this class was generated from the following file: