XRL  latest
Simple XML-RPC Library (both client and server)
Client.php
1 <?php
2 /*
3  * This file is part of XRL, a simple XML-RPC Library for PHP.
4  *
5  * Copyright (c) 2012, XRL Team. All rights reserved.
6  * XRL is licensed under the 3-clause BSD License.
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace fpoirotte\XRL;
13 
15 
47 class Client
48 {
50  protected $baseURL;
51 
53  protected $context;
54 
56  protected $encoder;
57 
59  protected $decoder;
60 
95  public function __construct(
96  $baseURL,
99  array $options = array()
100  ) {
101  if ($encoder === null) {
102  $encoder = new \fpoirotte\XRL\NativeEncoder(
103  new \fpoirotte\XRL\Encoder(null, false, true)
104  );
105  }
106 
107  if ($decoder === null) {
108  $decoder = new \fpoirotte\XRL\NativeDecoder(
109  new \fpoirotte\XRL\Decoder(null, true)
110  );
111  }
112 
113  $this->baseURL = $baseURL;
114  $this->options = $options;
115  $this->encoder = $encoder;
116  $this->decoder = $decoder;
117  }
118 
148  public function __call($method, array $args)
149  {
150  $newArgs = array_map('\\fpoirotte\\XRL\\NativeEncoder::convert', $args);
151  $request = new \fpoirotte\XRL\Request($method, $newArgs);
152  $xml = $this->encoder->encodeRequest($request);
153 
154  $headers = array(
155  'Content-Type: text/xml',
156  'User-Agent: XRL/' . \fpoirotte\XRL\CLI::getVersion(),
157  );
158 
159  $options = array(
160  'http' => array(
161  'method' => 'POST',
162  'content' => $xml,
163  'header' => $headers,
164  ),
165  );
166 
167  $options = array_merge_recursive($this->options, $options);
168  $context = stream_context_create($options);
169  libxml_set_streams_context($context);
170  return $this->decoder->decodeResponse($this->baseURL);
171  }
172 }
Interface for an XML-RPC decoder.
Interface for an XML-RPC encoder.
A simple XML-RPC client.
Definition: Client.php:47
An XML-RPC encoder that can produce either compact documents or pretty documents. ...
Definition: Encoder.php:21
__construct($baseURL,\fpoirotte\XRL\EncoderInterface $encoder=null,\fpoirotte\XRL\DecoderInterface $decoder=null, array $options=array())
Definition: Client.php:95
$encoder
Encoder for the request.
Definition: Client.php:56
$baseURL
The remote XML-RPC server&#39;s base URL.
Definition: Client.php:50
$decoder
Decoder for the response.
Definition: Client.php:59
__call($method, array $args)
Definition: Client.php:148
A decoder that can process XML-RPC requests and responses, with optional XML validation.
Definition: Decoder.php:21
static getVersion()
Definition: CLI.php:31
$context
A stream context to use when querying the server.
Definition: Client.php:53