/** * {@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; }
/** * Override __toString() to send HTTP Content-Type header * * @return string */ public function __toString() { if (!headers_sent()) { header('Content-Type: text/xml; charset=' . strtolower($this->getEncoding())); } return parent::__toString(); }
/** * 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(); }
/** * @group ZF-5404 */ public function testNilResponseFromXmlRpcServer() { $rawResponse = <<<EOD <methodResponse><params><param><value><array><data><value><struct><member><name>id</name><value><string>1</string></value></member><member><name>name</name><value><string>birdy num num!</string></value></member><member><name>description</name><value><nil/></value></member></struct></value></data></array></value></param></params></methodResponse> EOD; $response = new Response(); $ret = $response->loadXml($rawResponse); $this->assertTrue($ret); $this->assertEquals(array(0 => array('id' => 1, 'name' => 'birdy num num!', 'description' => null)), $response->getReturnValue()); }
public function getServerResponseFor($nativeVars) { $response = new XmlRpc\Response(); $response->setReturnValue($nativeVars); $xml = $response->saveXml(); $response = $this->makeHttpResponseFrom($xml); return $response; }
public function testShouldDisallowsDoctypeInRequestXmlAndReturnFalseOnLoading() { $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml'); $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt')); $this->assertFalse($this->_response->loadXml($payload)); }