4 * XMLRPC Client, very KISS
7 * NOTE: requires ext/xmlrpc
12 * $rpc = new XmlRpcClient('http://mike:secret@example.com/cgi-bin/vpop-xmlrpc');
13 * $rpc->__request->setOptions(array('compress' => true));
15 * print_r($rpc->vpop->listdomain(array('domain' => 'example.com')));
16 * } catch (Exception $ex) {
22 * @copyright Michael Wallner, <mike@iworks.at>
23 * @license BSD, revised
37 * HttpRequest instance
48 public $__encoding = "iso-8859-1";
53 * @param string $url RPC endpoint
54 * @param string $namespace RPC namespace
55 * @param array $options HttpRequest options
57 public function __construct($url, $namespace = '', array $options = null)
59 $this->__request
= new HttpRequest($url, HTTP_METH_POST
);
60 $this->__request
->setOptions($options);
61 $this->__namespace
= $namespace;
67 * @param string $method RPC method name
68 * @param array $params RPC method arguments
69 * @return mixed decoded RPC response
72 public function __call($method, array $params)
74 if ($this->__namespace
) {
75 $method = $this->__namespace
.'.'. $method;
77 $this->__request
->setContentType("text/xml; charset=". $this->__encoding
);
78 $request = xmlrpc_encode_request($method, $params, array("encoding" => $this->__encoding
));
79 $this->__request
->setRawPostData($request);
80 $this->__request
->send();
81 $response = $this->__request
->getResponseMessage();
82 if ($response->getResponseCode() != 200) {
84 $response->getResponseStatus(),
85 $response->getResponseCode()
89 $data = xmlrpc_decode($response->getBody(), $this->__encoding
);
90 if (xmlrpc_is_fault($data)) {
92 (string) $data['faultString'],
93 (int) $data['faultCode']
101 * Returns self, where namespace is set to variable name
104 * @return XmlRpcRequest
106 public function __get($ns)
108 $this->__namespace
= $ns;