PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 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 All 36 releases
← All changes | includes/sdk/s3/Aws/Api/Parser/RestJsonParser.php +18 -4 1.2.2 → 1.4.2 View file →
@@ -15,9 +15,9 @@
15 15 /**
16 16 * @param Service $api Service description
17 17 * @param JsonParser $parser JSON body builder
18 18 */
19 - public function __construct(Service $api, JsonParser $parser = null)
19 + public function __construct(Service $api, ?JsonParser $parser = null)
20 20 {
21 21 parent::__construct($api);
22 22 $this->parser = $parser ?: new JsonParser();
23 23 }
@@ -22,11 +22,25 @@
22 22 $this->parser = $parser ?: new JsonParser();
23 23 }
24 24 protected function payload(ResponseInterface $response, StructureShape $member, array &$result)
25 25 {
26 - $jsonBody = $this->parseJson($response->getBody(), $response);
27 - if ($jsonBody) {
28 - $result += $this->parser->parse($member, $jsonBody);
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);
29 43 }
30 44 }
31 45 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
32 46 {