summaryrefslogtreecommitdiff
path: root/framework/Util/TXmlRpcClient.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 21:46:23 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 21:46:23 +0100
commit001e69daef223679ad2331e61e78f45aec590f0a (patch)
treec26b6fe7cdca1d1749c439046124534fc27bf197 /framework/Util/TXmlRpcClient.php
parent1729b4bffedbcd0e0bdff80b74aa9944312d817c (diff)
One class per file: framework/Util
Diffstat (limited to 'framework/Util/TXmlRpcClient.php')
-rw-r--r--framework/Util/TXmlRpcClient.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/framework/Util/TXmlRpcClient.php b/framework/Util/TXmlRpcClient.php
new file mode 100644
index 00000000..de11d6a2
--- /dev/null
+++ b/framework/Util/TXmlRpcClient.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * @author Robin J. Rogge <rrogge@bigpoint.net>
+ * @link http://www.pradosoft.com/
+ * @copyright 2010 Bigpoint GmbH
+ * @license http://www.pradosoft.com/license/
+ * @since 3.2
+ * @package System.Util
+ */
+
+/**
+ * TXmlRpcClient class
+ *
+ * Note: When using setIsNotification(true), *every* following request is also
+ * considered to be a notification until you use setIsNotification(false).
+ *
+ * Usage:
+ * <pre>
+ * $_rpcClient = new TXmlRpcClient('http://remotehost/rpcserver');
+ * $_rpcClient->remoteMethod($param, $otherParam);
+ * </pre>
+ *
+ * @author Robin J. Rogge <rrogge@bigpoint.net>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.2
+ */
+
+class TXmlRpcClient extends TRpcClient
+{
+ // magics
+
+ /**
+ * @param string RPC method name
+ * @param array RPC method parameters
+ * @return mixed RPC request result
+ * @throws TRpcClientRequestException if the client fails to connect to the server
+ * @throws TRpcClientResponseException if the response represents an RPC fault
+ */
+ public function __call($method, $parameters)
+ {
+ // send request
+ $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml');
+
+ // skip response handling if the request was just a notification request
+ if($this->isNotification)
+ return true;
+
+ // decode response
+ if(($_response = xmlrpc_decode($_response)) === null)
+ throw new TRpcClientResponseException('Empty response received');
+
+ // handle error response
+ if(xmlrpc_is_fault($_response))
+ throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']);
+
+ return $_response;
+ }
+
+ // methods
+
+ /**
+ * @param string method name
+ * @param array method parameters
+ */
+ public function encodeRequest($method, $parameters)
+ {
+ return xmlrpc_encode_request($method, $parameters);
+ }
+
+ /**
+ * Creates an instance of TXmlRpcClient
+ * @param string url of the rpc server
+ * @param boolean whether the requests are considered to be notifications (completely ignoring the response) (default: false)
+ */
+ public static function create($type, $serverUrl, $isNotification = false)
+ {
+ return new self($serverUrl, $isNotification);
+ }
+} \ No newline at end of file