示例#1
0
 /**
  * Decode a request from XML and construct a request object with the createFromDecoded values
  *
  * @param SimpleXMLElement The encoded XML-RPC request.
  * @return XML_RPC2_Backend_Php_Request The xml-rpc request, represented as an object instance
  */
 public static function createFromDecode($simpleXML)
 {
     $methodName = (string) $simpleXML->methodName;
     $params = array();
     foreach ($simpleXML->params->param as $param) {
         foreach ($param->value as $value) {
             $params[] = XML_RPC2_Backend_Php_Value::createFromDecode($value)->getNativeValue();
         }
     }
     $result = new XML_RPC2_Backend_Php_Request($methodName);
     $result->setParameters($params);
     return $result;
 }
示例#2
0
 /**
  * Create a XML_RPC2_FaultException by decoding the corresponding xml string
  *
  * @param string $xml
  * @return object a XML_RPC2_FaultException
  */
 public static function createFromDecode($xml)
 {
     require_once 'XML/RPC2/Backend/Php/Value.php';
     // This is the only way I know of creating a new Document rooted in the provided simpleXMLFragment (needed for the xpath expressions that does not segfault sometimes
     $xml = simplexml_load_string($xml->asXML());
     $struct = XML_RPC2_Backend_Php_Value::createFromDecode($xml->value)->getNativeValue();
     if (!(is_array($struct) && array_key_exists('faultString', $struct) && array_key_exists('faultCode', $struct))) {
         throw new XML_RPC2_DecodeException('Unable to decode XML-RPC fault payload');
     }
     return new XML_RPC2_FaultException($struct['faultString'], $struct['faultCode']);
 }
示例#3
0
 /**
  * Parse a response and either return the native PHP result.
  *
  * This method receives an XML-RPC response document, in SimpleXML format, decodes it and returns the payload value.
  *
  * @param SimpleXmlElement $xml The Transport XML
  * @return mixed The response payload
  *
  * @see http://www.xmlrpc.com/spec
  * @throws XML_RPC2_FaultException Signals the decoded response was an XML-RPC fault
  * @throws XML_RPC2_DecodeException Signals an ill formed payload response section
  */
 public static function decode(SimpleXMLElement $xml)
 {
     $faultNode = $xml->xpath('/methodResponse/fault');
     if (count($faultNode) == 1) {
         throw XML_RPC2_FaultException::createFromDecode($faultNode[0]);
     }
     $paramValueNode = $xml->xpath('/methodResponse/params/param/value');
     if (count($paramValueNode) == 1) {
         return XML_RPC2_Backend_Php_Value::createFromDecode($paramValueNode[0])->getNativeValue();
     }
     throw new XML_RPC2_DecodeException('Unable to decode xml-rpc response. No fault nor params/param elements found');
 }
 /**
  * Decode transport XML and set the instance value accordingly
  *
  * @param mixed The encoded XML-RPC value,
  */
 public static function decode($xml)
 {
     // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
     // xpath is used both in an element and in one of its children
     $xml = simplexml_load_string($xml->asXML());
     $values = $xml->xpath('/value/struct/member');
     $result = array();
     foreach (array_keys($values) as $i) {
         $result[(string) $values[$i]->name] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i]->value)->getNativeValue();
     }
     return $result;
 }