Exception
11 months ago
AbstractParser.php
11 months ago
AbstractRestParser.php
11 months ago
Crc32ValidatingParser.php
11 months ago
DecodingEventStreamIterator.php
11 months ago
EventParsingIterator.php
11 months ago
JsonParser.php
11 months ago
JsonRpcParser.php
11 months ago
MetadataParserTrait.php
11 months ago
PayloadParserTrait.php
11 months ago
QueryParser.php
11 months ago
RestJsonParser.php
11 months ago
RestXmlParser.php
11 months ago
XmlParser.php
11 months ago
RestJsonParser.php
50 lines
| 1 | <?php |
| 2 | namespace Aws\Api\Parser; |
| 3 | |
| 4 | use Aws\Api\Service; |
| 5 | use Aws\Api\StructureShape; |
| 6 | use Psr\Http\Message\ResponseInterface; |
| 7 | use Psr\Http\Message\StreamInterface; |
| 8 | |
| 9 | /** |
| 10 | * @internal Implements REST-JSON parsing (e.g., Glacier, Elastic Transcoder) |
| 11 | */ |
| 12 | class RestJsonParser extends AbstractRestParser |
| 13 | { |
| 14 | use PayloadParserTrait; |
| 15 | |
| 16 | /** |
| 17 | * @param Service $api Service description |
| 18 | * @param JsonParser $parser JSON body builder |
| 19 | */ |
| 20 | public function __construct(Service $api, JsonParser $parser = null) |
| 21 | { |
| 22 | parent::__construct($api); |
| 23 | $this->parser = $parser ?: new JsonParser(); |
| 24 | } |
| 25 | |
| 26 | protected function payload( |
| 27 | ResponseInterface $response, |
| 28 | StructureShape $member, |
| 29 | array &$result |
| 30 | ) { |
| 31 | $jsonBody = $this->parseJson($response->getBody(), $response); |
| 32 | |
| 33 | if ($jsonBody) { |
| 34 | $result += $this->parser->parse($member, $jsonBody); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public function parseMemberFromStream( |
| 39 | StreamInterface $stream, |
| 40 | StructureShape $member, |
| 41 | $response |
| 42 | ) { |
| 43 | $jsonBody = $this->parseJson($stream, $response); |
| 44 | if ($jsonBody) { |
| 45 | return $this->parser->parse($member, $jsonBody); |
| 46 | } |
| 47 | return []; |
| 48 | } |
| 49 | } |
| 50 |