| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Api\Parser; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Api\Service; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape; |
| 7 |
use Dudlewebs\WPMCS\s3\Aws\Result; |
| 8 |
use Dudlewebs\WPMCS\s3\Aws\CommandInterface; |
| 9 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface; |
| 10 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface; |
| 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 |
/** @var bool */ |
| 18 |
private $honorResultWrapper; |
| 19 |
/** |
| 20 |
* @param Service $api Service description |
| 21 |
* @param XmlParser $xmlParser Optional XML parser |
| 22 |
* @param bool $honorResultWrapper Set to false to disable the peeling |
| 23 |
* back of result wrappers from the |
| 24 |
* output structure. |
| 25 |
*/ |
| 26 |
public function __construct(Service $api, XmlParser $xmlParser = null, $honorResultWrapper = \true) |
| 27 |
{ |
| 28 |
parent::__construct($api); |
| 29 |
$this->parser = $xmlParser ?: new XmlParser(); |
| 30 |
$this->honorResultWrapper = $honorResultWrapper; |
| 31 |
} |
| 32 |
public function __invoke(CommandInterface $command, ResponseInterface $response) |
| 33 |
{ |
| 34 |
$output = $this->api->getOperation($command->getName())->getOutput(); |
| 35 |
$xml = $this->parseXml($response->getBody(), $response); |
| 36 |
if ($this->honorResultWrapper && $output['resultWrapper']) { |
| 37 |
$xml = $xml->{$output['resultWrapper']}; |
| 38 |
} |
| 39 |
return new Result($this->parser->parse($output, $xml)); |
| 40 |
} |
| 41 |
public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response) |
| 42 |
{ |
| 43 |
$xml = $this->parseXml($stream, $response); |
| 44 |
return $this->parser->parse($member, $xml); |
| 45 |
} |
| 46 |
} |
| 47 |
|