/** * Perform an XML-RPC request and return a response. * * @param \Zend\XmlRpc\Request $request * @param null|\Zend\XmlRpc\Response $response * @return void * @throws \Zend\XmlRpc\Client\Exception\HttpException */ public function doRequest($request, $response = null) { $this->lastRequest = $request; if (PHP_VERSION_ID < 50600) { iconv_set_encoding('input_encoding', 'UTF-8'); iconv_set_encoding('output_encoding', 'UTF-8'); iconv_set_encoding('internal_encoding', 'UTF-8'); } else { ini_set('default_charset', 'UTF-8'); } $http = $this->getHttpClient(); $httpRequest = $http->getRequest(); if ($httpRequest->getUriString() === null) { $http->setUri($this->serverAddress); } $headers = $httpRequest->getHeaders(); $headers->addHeaders(array('Content-Type: text/xml; charset=utf-8', 'Accept: text/xml')); if (!$headers->get('user-agent')) { $headers->addHeaderLine('user-agent', 'Zend_XmlRpc_Client'); } $xml = $this->lastRequest->__toString(); $http->setRawBody($xml); $httpResponse = $http->setMethod('POST')->send(); if (!$httpResponse->isSuccess()) { /** * Exception thrown when an HTTP error occurs */ throw new Client\Exception\HttpException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode()); } if ($response === null) { $response = new Response(); } $this->lastResponse = $response; $this->lastResponse->loadXml(trim($httpResponse->getBody())); }
/** * {@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; }
/** * @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 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)); }