- improve handling of xmlrpc request/response options
authorMichael Wallner <mike@php.net>
Mon, 15 Jan 2007 08:01:35 +0000 (08:01 +0000)
committerMichael Wallner <mike@php.net>
Mon, 15 Jan 2007 08:01:35 +0000 (08:01 +0000)
lib/XmlRpcClient.php
lib/XmlRpcServer.php

index 488e1cf..8668291 100644 (file)
@@ -47,6 +47,13 @@ class XmlRpcClient
         */
        public $__encoding = "iso-8859-1";
        
+       /**
+        * RPC options
+        * 
+        * @var array
+        */
+       public $__options;
+       
        /**
         * Constructor
         *
@@ -54,9 +61,9 @@ class XmlRpcClient
         * @param string $namespace RPC namespace
         * @param array  $options HttpRequest options
         */
-       public function __construct($url, $namespace = '', array $options = array())
+       public function __construct($url, $namespace = '', array $options = null)
        {
-               $this->__request = new HttpRequest($url, HttpRequest::METH_POST, $options);
+               $this->__request = new HttpRequest($url, HttpRequest::METH_POST, (array) $options);
                $this->__namespace = $namespace;
        }
        
@@ -76,7 +83,7 @@ class XmlRpcClient
                $this->__request->setContentType("text/xml");
                $this->__request->setRawPostData(
                        xmlrpc_encode_request($method, $params, 
-                               array("encoding" => $this->__encoding)));
+                               array("encoding" => $this->__encoding) + (array) $this->__options));
                $response = $this->__request->send();
                if ($response->getResponseCode() != 200) {
                        throw new Exception(
index a9f7505..c8c1ac4 100644 (file)
@@ -110,12 +110,13 @@ class XmlRpcServer extends HttpResponse
         *
         * @param string $method
         * @param array $params
-        * @param array $options
+        * @param array $request_options
+        * @param array $response_options
         */
-       public static function test($method, array $params, array $options = null)
+       public static function test($method, array $params, array $request_options = null, array $response_options = null)
        {
-               self::$xmlreq = xmlrpc_encode_request($method, $params);
-               self::run();
+               self::$xmlreq = xmlrpc_encode_request($method, $params, $request_options);
+               self::run($response_options);
        }
        
        /**
@@ -124,9 +125,10 @@ class XmlRpcServer extends HttpResponse
         * @param int $code
         * @param string $msg
         */
-       public static function error($code, $msg)
+       public static function error($code, $msg, array $options = null)
        {
-               echo xmlrpc_encode(array("faultCode" => $code, "faultString" => $msg));
+               echo xmlrpc_encode(array("faultCode" => $code, "faultString" => $msg),
+                       array("encoding" => self::$encoding) + (array) $options);
        }
        
        /**