Пример #1
0
 /**
  * __call Catchall. This method catches remote method calls and provides for remote forwarding.
  *
  * If the parameters are native types, this method will use XML_RPC_Value::createFromNative to 
  * convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value
  * it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative
  * proves inacurate -- as when encoding DateTime values -- you should present an instance of 
  * XML_RPC_Value in lieu of the native parameter.
  *
  * @param   string      Method name
  * @param   array       Parameters
  * @return  mixed       The call result, already decoded into native types
  */
 public function __call($methodName, $parameters)
 {
     $tmp = xmlrpc_encode_request($this->prefix . $methodName, $parameters, array('escaping' => $this->escaping, 'encoding' => $this->encoding));
     if ($this->uglyStructHack) {
         // ugly hack because of http://bugs.php.net/bug.php?id=21949
         // see XML_RPC2_Backend_Xmlrpcext_Value::createFromNative() from more infos
         $request = preg_replace('~<name>xml_rpc2_ugly_struct_hack_(.*)</name>~', '<name>\\1</name>', $tmp);
     } else {
         $request = $tmp;
     }
     $uri = $this->uri;
     $options = array('encoding' => $this->encoding, 'proxy' => $this->proxy, 'sslverify' => $this->sslverify, 'connectionTimeout' => $this->connectionTimeout);
     if (isset($this->httpRequest)) {
         $options['httpRequest'] = $this->httpRequest;
     }
     $httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
     $httpRequest->setPostData($request);
     $httpRequest->sendRequest();
     $body = $httpRequest->getBody();
     if ($this->debug) {
         XML_RPC2_ClientHelper::printPreParseDebugInfo($request, $body);
     }
     $result = xmlrpc_decode($body, $this->encoding);
     /* Commented due to change in behaviour from xmlrpc_decode. It does not return faults now
        if ($result === false || is_null($result)) {
            if ($this->debug) {
                print "XML_RPC2_Exception : unable to decode response !";
            }
            throw new XML_RPC2_Exception('Unable to decode response');
        }
        */
     if (is_array($result) && xmlrpc_is_fault($result)) {
         if ($this->debug) {
             print "XML_RPC2_FaultException({$result['faultString']}, {$result['faultCode']})";
         }
         throw new XML_RPC2_FaultException($result['faultString'], $result['faultCode']);
     }
     if ($this->debug) {
         XML_RPC2_ClientHelper::printPostRequestDebugInformation($result);
     }
     return $result;
 }
 /**
  * __call Catchall. This method catches remote method calls and provides for remote forwarding.
  *
  * If the parameters are native types, this method will use XML_RPC_Value::createFromNative to 
  * convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value
  * it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative
  * proves inacurate -- as when encoding DateTime values -- you should present an instance of 
  * XML_RPC_Value in lieu of the native parameter.
  *
  * @param   string      Method name
  * @param   array       Parameters
  * @return  mixed       The call result, already decoded into native types
  */
 public function __call($methodName, $parameters)
 {
     $request = new XML_RPC2_Backend_Php_Request($this->prefix . $methodName, $this->encoding);
     $request->setParameters($parameters);
     $request = $request->encode();
     $uri = $this->uri;
     $options = array('encoding' => $this->encoding, 'proxy' => $this->proxy, 'sslverify' => $this->sslverify, 'connectionTimeout' => $this->connectionTimeout);
     if (isset($this->httpRequest)) {
         $options['httpRequest'] = $this->httpRequest;
     }
     $httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
     $httpRequest->setPostData($request);
     $httpRequest->sendRequest();
     $body = $httpRequest->getBody();
     if ($this->debug) {
         XML_RPC2_ClientHelper::printPreParseDebugInfo($request, $body);
     }
     try {
         $document = new SimpleXMLElement($body);
         $result = XML_RPC2_Backend_Php_Response::decode($document);
     } catch (XML_RPC2_Exception $e) {
         if ($this->debug) {
             if (get_class($e) == 'XML_RPC2_FaultException') {
                 print "XML_RPC2_FaultException #" . $e->getFaultCode() . " : " . $e->getMessage();
             } else {
                 print get_class($e) . " : " . $e->getMessage();
             }
         }
         throw $e;
     }
     if ($this->debug) {
         XML_RPC2_ClientHelper::printPostRequestDebugInformation($result);
     }
     return $result;
 }
 /**
  * Construct a new XML_RPC2_Client.
  *
  * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/).
  * Optionally, some options may be set as an associative array. Accepted keys are :
  * 'prefix', 'proxy', 'debug' => see correspondant property to get more informations
  * 'encoding' => The XML encoding for the requests (optional, defaults to utf-8)
  * 'sslverify' => boolean, true iff SSL certificates are to be verified against local cert database (optional, default false)
  * 'connectionTimeout' => Timeout, in seconds, for the XML-RPC HTTP request (optional, default is no timeout)
  * 'httpRequest' => Preconfigured HTTP_Request2 instance to be used in executing the XML-RPC calls (optional)
  *
  * @param string URI for the XML-RPC server
  * @param array (optional) Associative array of options
  */
 protected function __construct($uri, $options = array())
 {
     if (!($uriParse = parse_url($uri))) {
         throw new XML_RPC2_InvalidUriException(sprintf('Client URI \'%s\' is not valid', $uri));
     }
     $this->uri = $uri;
     if (isset($options['prefix'])) {
         if (!XML_RPC2_ClientHelper::testMethodName($options['prefix'])) {
             throw new XML_RPC2_InvalidPrefixException(sprintf('Prefix \'%s\' is not valid', $options['prefix']));
         }
         $this->prefix = $options['prefix'];
     }
     if (isset($options['proxy'])) {
         if (!($proxyParse = parse_url($options['proxy']))) {
             throw new XML_RPC2_InvalidProxyException(sprintf('Proxy URI \'%s\' is not valid', $options['proxy']));
         }
         $this->proxy = $options['proxy'];
     }
     if (isset($options['debug'])) {
         if (!is_bool($options['debug'])) {
             throw new XML_RPC2_InvalidDebugException(sprintf('Debug \'%s\' is not valid', $options['debug']));
         }
         $this->debug = $options['debug'];
     }
     if (isset($options['encoding'])) {
         // TODO : control & exception
         $this->encoding = $options['encoding'];
     }
     if (isset($options['escaping'])) {
         // TODO : control & exception
         $this->escaping = $options['escaping'];
     }
     if (isset($options['uglyStructHack'])) {
         $this->uglyStructHack = $options['uglyStructHack'];
     }
     if (isset($options['sslverify'])) {
         if (!is_bool($options['sslverify'])) {
             throw new XML_RPC2_InvalidSslverifyException(sprintf('SSL verify \'%s\' is not valid', $options['sslverify']));
         }
         $this->sslverify = $options['sslverify'];
     }
     if (isset($options['connectionTimeout'])) {
         if (!is_int($options['connectionTimeout'])) {
             throw new XML_RPC2_InvalidConnectionTimeoutException(sprintf('Connection timeout \'%s\' is not valid', $options['connectionTimeout']));
         }
         $this->connectionTimeout = $options['connectionTimeout'];
     }
     if (isset($options['httpRequest'])) {
         $this->httpRequest = $options['httpRequest'];
     }
 }