| 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 |
|
| 13 |
|
| 14 |
class QueryParser extends AbstractParser |
| 15 |
{ |
| 16 |
use PayloadParserTrait; |
| 17 |
|
| 18 |
|
| 19 |
private $honorResultWrapper; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 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 |
|
| 44 |
$rawBody = AbstractParser::getBodyContents($response); |
| 45 |
|
| 46 |
$xml = !empty($rawBody) |
| 47 |
? $this->parseXml($rawBody, $response) |
| 48 |
: null; |
| 49 |
|
| 50 |
|
| 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 |
} |