本文整理汇总了PHP中GuzzleHttp\Message\Response::xml方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::xml方法的具体用法?PHP Response::xml怎么用?PHP Response::xml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\Response
的用法示例。
在下文中一共展示了Response::xml方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: contentToProperty
/**
* Converts the <content> section to an array and stores as an object property.
*/
private function contentToProperty()
{
$xml_response = json_decode(json_encode((array) $this->http_response_object->xml()), 1);
if (isset($xml_response['content'])) {
$this->xmws_content_array = $xml_response['content'];
$this->xmws_content_string = $xml_response['content'];
}
}
示例2: 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;
}
示例3: parseResponse
/**
* Parse the returned response.
*
* @param \GuzzleHttp\Message\Response $response
* @return array
*
* @throws \RuntimeException
*/
protected function parseResponse(Response $response)
{
$contentType = explode(';', $response->getHeader('content-type'))[0];
switch ($contentType) {
case 'text/javascript':
case 'application/json':
return $response->json();
case 'application/xml':
return $response->xml();
}
throw new \RuntimeException("Unsupported returned content-type [{$contentType}]");
}
示例4: 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(), Stream::factory($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);
}
}
示例5: __construct
/**
* Construct a Ping response from an HTTP response.
*
* @param Response $response
*/
public function __construct(Response $response)
{
$this->response = $response;
$this->status = $response->getStatusCode();
$this->error = null;
$this->xml = null;
$this->body = $response->getBody();
try {
$this->xml = $response->xml();
} catch (Exception $ex) {
$this->error = $ex->getMessage();
} catch (XmlParseException $ex) {
$this->error = $ex->getMessage();
}
}
示例6: parseBody
/**
* {@inheritdoc}
*/
public function parseBody(Response $response, $format = '')
{
$output = NULL;
if (empty($format)) {
$format = isset($this->defaults['form']) ? $this->defaults['form'] : NULL;
}
if ($format == $this::FORMAT_JSON || $format == $this::FORMAT_CJSON) {
$output = $response->json();
}
if ($format == $this::FORMAT_ATOM || $format == $this::FORMAT_RSS) {
$output = $this->xmlToArray($response->xml());
}
if ($output['isException']) {
throw new MpxException(sprintf('Exception returned: %s', print_r($output, TRUE)), $output['responseCode']);
}
if (isset($output)) {
return $output;
}
throw new MpxException('Custom formats are not supported.');
}
示例7: decodeRequest
/**
* Decodes the API response from XML to a JSON array.
*
* @param Response $response
* @return array
*/
protected function decodeRequest(Response $response)
{
// check if XML received
$xml = $response->xml();
return json_decode(json_encode($xml), true);
}
示例8: detectType
private function detectType(\GuzzleHttp\Message\Response $response)
{
switch ($response->getHeader('content-type')) {
case 'application/json':
return $response->json();
break;
case 'application/xml':
case 'text/xml':
return json_decode(json_encode($response->xml()), true);
break;
default:
return $response->getBody();
}
}