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";
60 * @param string $url RPC endpoint
61 * @param string $namespace RPC namespace
62 * @param array $options HttpRequest options
64 public function __construct($url, $namespace = '', array $options = null)
66 $this->__request
= new HttpRequest($url, HttpRequest
::METH_POST
, (array) $options);
67 $this->__namespace
= $namespace;
73 * @param string $method RPC method name
74 * @param array $params RPC method arguments
75 * @return mixed decoded RPC response
78 public function __call($method, array $params)
80 if (strlen($this->__namespace
)) {
81 $method = $this->__namespace
.'.'. $method;
83 $this->__request
->setContentType("text/xml");
84 $this->__request
->setRawPostData(
85 xmlrpc_encode_request($method, $params,
86 array("encoding" => $this->__encoding
) +
(array) $this->__options
));
87 $response = $this->__request
->send();
88 if ($response->getResponseCode() != 200) {
90 $response->getResponseStatus(),
91 $response->getResponseCode()
95 $data = xmlrpc_decode($response->getBody(), $this->__encoding
);
96 if (xmlrpc_is_fault($data)) {
98 (string) $data['faultString'],
99 (int) $data['faultCode']
107 * Returns self, where namespace is set to variable name
110 * @return XmlRpcRequest
112 public function __get($ns)
114 $this->__namespace
= $ns;