/**
  * __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;
 }
Ejemplo n.º 2
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;
 }