/** * @param Response $response * * @return string */ protected static function createMessage(Response $response) { if ($response->getStatusCode() != 400) { return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true); } $message = 'Some errors occurred:'; foreach ($response->xml()->error as $error) { $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message; } return $message; }
/** * {@inheritdoc} */ public function xml() { try { $result = $this->response->xml(); } catch (\Exception $exception) { throw GuzzleRestException::createFromException($exception); } return $result; }
private function getContent(Response $response) { if ($response->isContentType('xml')) { return $response->xml(); } elseif ($response->isContentType('audio')) { return $response->getBody()->getStream(); } else { return $response->getBody(); } }
public function decodeResponse(Response $response) { $rootElement = dom_import_simplexml($response->xml()); $doc = $rootElement->ownerDocument; $xpath = new DOMXPath($doc); $faultElement = $xpath->query("/methodResponse/fault"); if ($faultElement->length > 0) { $errorCodeList = $xpath->query("/methodResponse/fault[1]/value[1]/struct[1]/member[name='faultCode']/value/int"); $errorMessageList = $xpath->query("/methodResponse/fault[1]/value[1]/struct[1]/member[name='faultString']/value/string"); $errorCode = $errorCodeList->length > 0 ? (int) $errorCodeList->item(0)->nodeValue : null; $errorMessage = $errorMessageList->length > 0 ? (string) $errorMessageList->item(0)->nodeValue : ""; throw new RpcErrorException($errorMessage, $errorCode); } if (($params = $xpath->evaluate("/methodResponse/params/param")) instanceof DomNodeList && $params->length > 0) { $results = array(); foreach ($params as $paramElement) { $results[] = $this->parameterDeserializer->getValueFromDomElement($paramElement); } return $results; } throw new RpcNoResultException(); }
/** * @covers Guzzle\Http\Message\Response::xml * @expectedException \Guzzle\Common\Exception\RuntimeException * @expectedExceptionMessage Unable to parse response body into XML: String could not be parsed as XML */ public function testThrowsExceptionWhenFailsToParseXmlResponse() { $response = new Response(200, array(), '<abc'); $response->xml(); }
public function testPreventsComplexExternalEntities() { $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>'; $response = new Response(200, array(), $xml); $oldCwd = getcwd(); chdir(__DIR__); try { $xml = $response->xml(); chdir($oldCwd); $this->markTestIncomplete('Did not throw the expected exception! XML resolved as: ' . $xml->asXML()); } catch (\Exception $e) { chdir($oldCwd); } }
/** * @param Response $response * @return \SimpleXMLElement */ public static function getContent(Response $response) { return $response->xml(); }
public function __construct(RequestInterface $request, HttpResponse $response) { parent::__construct($request, $response->xml()); $this->isSuccessful = $response->isSuccessful(); }
/** * @expectedException \Guzzle\Common\Exception\RuntimeException */ public function testPreventsComplexExternalEntities() { $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>'; $response = new Response(200, array(), $xml); $oldCwd = getcwd(); chdir(__DIR__); try { $response->xml(); chdir($oldCwd); } catch (\Exception $e) { chdir($oldCwd); throw $e; } }