本文整理汇总了PHP中Guzzle\Http\Message\Response::xml方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::xml方法的具体用法?PHP Response::xml怎么用?PHP Response::xml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::xml方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xml
/**
* {@inheritdoc}
*/
public function xml()
{
try {
$result = $this->response->xml();
} catch (\Exception $exception) {
throw GuzzleRestException::createFromException($exception);
}
return $result;
}
示例2: getContent
private function getContent(Response $response)
{
if ($response->isContentType('xml')) {
return $response->xml();
} elseif ($response->isContentType('audio')) {
return $response->getBody()->getStream();
} else {
return $response->getBody();
}
}
示例3: createMessage
/**
* @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;
}
示例4: decodeResponse
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();
}
示例5: testThrowsExceptionWhenFailsToParseXmlResponse
/**
* @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();
}
示例6: testPreventsComplexExternalEntities
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);
}
}
示例7: getContent
/**
* @param Response $response
* @return \SimpleXMLElement
*/
public static function getContent(Response $response)
{
return $response->xml();
}
示例8: __construct
public function __construct(RequestInterface $request, HttpResponse $response)
{
parent::__construct($request, $response->xml());
$this->isSuccessful = $response->isSuccessful();
}
示例9: testPreventsComplexExternalEntities
/**
* @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;
}
}