4 * XMLRPC Client, very KISS
7 * NOTE: requires ext/xmlrpc
12 * $rpc = new XmlRpcClient('http://mike:secret@example.com/cgi-bin/vpop-xmlrpc', 'vpop');
14 * print_r($rpc->listdomain(array('domain' => 'example.com')));
15 * } catch (Exception $ex) {
21 * @copyright Michael Wallner, <mike@iworks.at>
22 * @license BSD, revised
36 * HttpRequest instance
45 * @param string $url RPC endpoint
46 * @param string $namespace RPC namespace
48 public function __construct($url, $namespace = '')
50 $this->namespace = $namespace;
51 $this->request
= new HttpRequest($url, HTTP_METH_POST
);
52 $this->request
->setContentType('text/xml');
56 * Proxy to HttpRequest::setOptions()
58 * @param array $options
61 public function setOptions(array $options = null)
63 return $this->request
->setOptions($options);
67 * Get associated HttpRequest instance
71 public function getRequest()
73 return $this->request
;
79 * @param string $method RPC method name
80 * @param array $params RPC method arguments
81 * @return mixed decoded RPC response
84 public function __call($method, array $params)
86 if ($this->namespace) {
87 $method = $this->namespace .'.'. $method;
89 $this->request
->setRawPostData(xmlrpc_encode_request($method, $params));
90 $response = $this->request
->send();
91 if ($response->getResponseCode() != 200) {
92 throw new Exception($response->getBody(), $response->getResponseCode());
94 return xmlrpc_decode($response->getBody(), 'utf-8');