Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Parser/QueryParser.php

raw symbols SCIP
1 <?php
2 namespace Aws\Api\Parser;
3
4 use Aws\Api\Service;
5 use Aws\Api\StructureShape;
6 use Aws\Result;
7 use Aws\CommandInterface;
8 use Psr\Http\Message\ResponseInterface;
9 use Psr\Http\Message\StreamInterface;
10
11 /**
12 * @internal Parses query (XML) responses (e.g., EC2, SQS, and many others)
13 */
14 class QueryParser extends AbstractParser
15 {
16 use PayloadParserTrait;
17
18 /** @var bool */
19 private $honorResultWrapper;
20
21 /**
22 * @param Service $api Service description
23 * @param XmlParser $xmlParser Optional XML parser
24 * @param bool $honorResultWrapper Set to false to disable the peeling
25 * back of result wrappers from the
26 * output structure.
27 */
28 public function __construct(
29 Service $api,
30 ?XmlParser $xmlParser = null,
31 $honorResultWrapper = true
32 ) {
33 parent::__construct($api);
34 $this->parser = $xmlParser ?: new XmlParser();
35 $this->honorResultWrapper = $honorResultWrapper;
36 }
37
38 public function __invoke(
39 CommandInterface $command,
40 ResponseInterface $response
41 ) {
42 $output = $this->api->getOperation($command->getName())->getOutput();
43 // Read the full payload, even in non-seekable streams
44 $rawBody = AbstractParser::getBodyContents($response);
45 // Just parse when the body is not empty
46 $xml = !empty($rawBody)
47 ? $this->parseXml($rawBody, $response)
48 : null;
49
50 // Empty request bodies should not be deserialized.
51 if (is_null($xml)) {
52 return new Result();
53 }
54
55 if ($this->honorResultWrapper && $output['resultWrapper']) {
56 $xml = $xml->{$output['resultWrapper']};
57 }
58
59 return new Result($this->parser->parse($output, $xml));
60 }
61
62 public function parseMemberFromStream(
63 StreamInterface $stream,
64 StructureShape $member,
65 $response
66 ) {
67 $xml = $this->parseXml($stream, $response);
68 return $this->parser->parse($member, $xml);
69 }
70 }