PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Parser / RestJsonParser.php

RestJsonParser.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/Api/Parser/RestJsonParser.php

54 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Psr\Http\Message\ResponseInterface;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
9 /**
10 * @internal Implements REST-JSON parsing (e.g., Glacier, Elastic Transcoder)
11 */
12 class RestJsonParser extends AbstractRestParser
13 {
14 use PayloadParserTrait;
15 /**
16 * @param Service $api Service description
17 * @param JsonParser $parser JSON body builder
18 */
19 public function __construct(Service $api, ?JsonParser $parser = null)
20 {
21 parent::__construct($api);
22 $this->parser = $parser ?: new JsonParser();
23 }
24 protected function payload(ResponseInterface $response, StructureShape $member, array &$result)
25 {
26 $responseBody = (string) $response->getBody();
27 // Parse JSON if we have content
28 $parsedJson = null;
29 if (!empty($responseBody)) {
30 $parsedJson = $this->parseJson($responseBody, $response);
31 } else {
32 // An empty response body should be deserialized as null
33 $result = $parsedJson;
34 return;
35 }
36 $parsedBody = $this->parser->parse($member, $parsedJson);
37 if (\is_string($parsedBody) && $member['document']) {
38 // Document types can be strings: replace entire result
39 $result = $parsedBody;
40 } else {
41 // Merge array/object results into existing result
42 $result = \array_merge($result, (array) $parsedBody);
43 }
44 }
45 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
46 {
47 $jsonBody = $this->parseJson($stream, $response);
48 if ($jsonBody) {
49 return $this->parser->parse($member, $jsonBody);
50 }
51 return [];
52 }
53 }
54