/** * {@inheritdoc} */ public function parse($xmlString) { $response = new Response(); try { $response->loadXml($xmlString); } catch (\Exception $e) { throw new ParserException($e->getMessage(), $e->getCode(), $e); } if ($response->isFault()) { $fault = $response->getFault(); throw new FaultException($fault->getMessage(), $fault->getCode()); } $result = $response->getReturnValue(); $toBeVisited = [&$result]; while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) { $type = gettype($value); if ($type === 'array') { foreach ($value as &$element) { $toBeVisited[] =& $element; } reset($value); // Reset all array pointers } array_shift($toBeVisited); } return $result; }
public function testLoadXmlThrowsExceptionWithMissingNodes3() { $sxl = new \SimpleXMLElement('<?xml version="1.0"?><methodResponse><bar>foo</bar></methodResponse>'); $this->assertFalse($this->_response->loadXml($sxl->asXML())); $this->assertTrue($this->_response->isFault()); $fault = $this->_response->getFault(); $this->assertEquals(652, $fault->getCode()); }
/** * Send an XML-RPC request to the service (for a specific method) * * @param string $method Name of the method we want to call * @param array $params Array of parameters for the method * @return mixed * @throws \Zend\XmlRpc\Client\Exception\FaultException */ public function call($method, $params = array()) { if (!$this->skipSystemLookup() && 'system.' != substr($method, 0, 7)) { // Ensure empty array/struct params are cast correctly // If system.* methods are not available, bypass. (ZF-2978) $success = true; try { $signatures = $this->getIntrospector()->getMethodSignature($method); } catch (\Zend\XmlRpc\Exception\ExceptionInterface $e) { $success = false; } if ($success) { $validTypes = array(AbstractValue::XMLRPC_TYPE_ARRAY, AbstractValue::XMLRPC_TYPE_BASE64, AbstractValue::XMLRPC_TYPE_BOOLEAN, AbstractValue::XMLRPC_TYPE_DATETIME, AbstractValue::XMLRPC_TYPE_DOUBLE, AbstractValue::XMLRPC_TYPE_I4, AbstractValue::XMLRPC_TYPE_INTEGER, AbstractValue::XMLRPC_TYPE_NIL, AbstractValue::XMLRPC_TYPE_STRING, AbstractValue::XMLRPC_TYPE_STRUCT); if (!is_array($params)) { $params = array($params); } foreach ($params as $key => $param) { if ($param instanceof AbstractValue) { continue; } if (count($signatures) > 1) { $type = AbstractValue::getXmlRpcTypeByValue($param); foreach ($signatures as $signature) { if (!is_array($signature)) { continue; } if (isset($signature['parameters'][$key])) { if ($signature['parameters'][$key] == $type) { break; } } } } elseif (isset($signatures[0]['parameters'][$key])) { $type = $signatures[0]['parameters'][$key]; } else { $type = null; } if (empty($type) || !in_array($type, $validTypes)) { $type = AbstractValue::AUTO_DETECT_TYPE; } $params[$key] = AbstractValue::getXmlRpcValue($param, $type); } } } $request = $this->_createRequest($method, $params); $this->doRequest($request); if ($this->lastResponse->isFault()) { $fault = $this->lastResponse->getFault(); /** * Exception thrown when an XML-RPC fault is returned */ throw new Client\Exception\FaultException($fault->getMessage(), $fault->getCode()); } return $this->lastResponse->getReturnValue(); }