Ejemplo n.º 1
0
 /**
  * Parse the response from a XML-RPC method call, hold the response as a Zend_XmlRpc_Value object
  * The response parameter must be a valid XML string
  *
  * @param string $response XML string to parse
  */
 protected function _parseResponse($response)
 {
     if (!$response) {
         // The response is empty
         throw new Zend_XmlRpc_Client_Exception('Received empty response');
     }
     // Using simple XML to parse the response
     try {
         $simple_xml = @new SimpleXMLElement($response);
     } catch (Exception $e) {
         // The response is not a valid XML
         throw new Zend_XmlRpc_Client_Exception('Failed to parse response: ' . $e->getMessage(), $e->getCode());
     }
     // We check if this is a Fault response
     if (!empty($simple_xml->fault)) {
         // The fault tag exists and not empty, the request failed and returned a fault response
         if (empty($simple_xml->fault->value)) {
             // Invalid fault response, fault tag must contain a value tag
             throw new Zend_XmlRpc_Client_Exception('Invalid fault response, FAULT tag must contain a VALUE tag');
         }
         // Parse the fault response into a Zend_XmlRpc_Value object
         try {
             $this->_response = Zend_XmlRpc_Value::getXmlRpcValue($simple_xml->fault->value, Zend_XmlRpc_Value::XML_STRING);
         } catch (Zend_XmlRpc_Value_Exception $e) {
             // Failed to create a Zend_XmlRpc_Value object from the fault
             throw new Zend_XmlRpc_Client_Exception('Invalid fault response, ' . $e->getMessage());
         }
         $fault = $this->_response->getValue();
         throw new Zend_XmlRpc_Client_Exception('Request failed, ' . $fault['faultString'], $fault['faultCode']);
     } elseif (empty($simple_xml->params)) {
         // Invalid response, no params tag
         throw new Zend_XmlRpc_Client_Exception('Invalid response, method response must contain a PARAMS tag');
     } elseif (empty($simple_xml->params->param)) {
         // Invalid response, params tag must contain a param tag
         throw new Zend_XmlRpc_Client_Exception('Invalid response, PARAMS tag must contain a PARAM tag');
     } elseif (empty($simple_xml->params->param->value)) {
         // Invalid response, param tag must contain a value tag
         throw new Zend_XmlRpc_Client_Exception('Invalid response, PARAM tag must contain a VALUE tag');
     }
     // Parse the success response into a Zend_XmlRpc_Value object
     $this->_response = Zend_XmlRpc_Value::getXmlRpcValue($simple_xml->params->param->value, Zend_XmlRpc_Value::XML_STRING);
     return $this->__getResponse(self::RESPONSE_PHP_NATIVE);
 }