- examples fixup
[m6w6/ext-http] / docs / examples / KISS_XMLRPC_Client.php
1 <?php
2 class XmlRpcClient
3 {
4 public $namespace;
5 protected $request;
6
7 public function __construct($url, $namespace = '')
8 {
9 $this->namespace = $namespace;
10 $this->request = new HttpRequest($url, HTTP_METH_POST);
11 $this->request->setContentType('text/xml');
12 }
13
14 public function setOptions($options = array())
15 {
16 return $this->request->setOptions($options);
17 }
18
19 public function addOptions($options)
20 {
21 return $this->request->addOptions($options);
22 }
23
24 public function __call($method, $params)
25 {
26 if ($this->namespace) {
27 $method = $this->namespace .'.'. $method;
28 }
29 $this->request->setRawPostData(xmlrpc_encode_request($method, $params));
30 $response = $this->request->send();
31 if ($response->getResponseCode() != 200) {
32 throw new Exception($response->getBody(), $response->getResponseCode());
33 }
34 return xmlrpc_decode($response->getBody(), 'utf-8');
35 }
36
37 public function getHistory()
38 {
39 return $this->request->getHistory();
40 }
41 }
42
43 ?>