← All changes
|
includes/sdk/s3/Aws/Api/Parser/AbstractRestParser.php
+34
-11
1.2.7
→
1.4.2
View file →
| @@ -43,9 +43,10 @@ | ||
| 43 | 43 | $this->extractStatus($name, $response, $result); |
| 44 | 44 | break; |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - if (!$payload && $response->getBody()->getSize() > 0 && \count($output->getMembers()) > 0) { | |
| 47 | + $body = $response->getBody(); | |
| 48 | + if (!$payload && (!$body->isSeekable() || $body->getSize()) && \count($output->getMembers()) > 0) { | |
| 48 | 49 | // if no payload was found, then parse the contents of the body |
| 49 | 50 | $this->payload($response, $output, $result); |
| 50 | 51 | } |
| 51 | 52 | return new Result($result); |
| @@ -52,19 +53,22 @@ | ||
| 52 | 53 | } |
| 53 | 54 | private function extractPayload($payload, StructureShape $output, ResponseInterface $response, array &$result) |
| 54 | 55 | { |
| 55 | 56 | $member = $output->getMember($payload); |
| 57 | + $body = $response->getBody(); | |
| 56 | 58 | if (!empty($member['eventstream'])) { |
| 57 | - $result[$payload] = new EventParsingIterator($response->getBody(), $member, $this); | |
| 59 | + $result[$payload] = new EventParsingIterator($body, $member, $this); | |
| 60 | + } elseif ($member instanceof StructureShape) { | |
| 61 | + //Unions must have at least one member set to a non-null value | |
| 62 | + // If the body is empty, we can assume it is unset | |
| 63 | + if (!empty($member['union']) && ($body->isSeekable() && !$body->getSize())) { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + $result[$payload] = []; | |
| 67 | + $this->payload($response, $member, $result[$payload]); | |
| 58 | 68 | } else { |
| 59 | - if ($member instanceof StructureShape) { | |
| 60 | - // Structure members parse top-level data into a specific key. | |
| 61 | - $result[$payload] = []; | |
| 62 | - $this->payload($response, $member, $result[$payload]); | |
| 63 | - } else { | |
| 64 | - // Streaming data is just the stream from the response body. | |
| 65 | - $result[$payload] = $response->getBody(); | |
| 66 | - } | |
| 69 | + // Always set the payload to the body stream, regardless of content | |
| 70 | + $result[$payload] = $body; | |
| 67 | 71 | } |
| 68 | 72 | } |
| 69 | 73 | /** |
| 70 | 74 | * Extract a single header from the response into the result. |
| @@ -71,14 +75,22 @@ | ||
| 71 | 75 | */ |
| 72 | 76 | private function extractHeader($name, Shape $shape, ResponseInterface $response, &$result) |
| 73 | 77 | { |
| 74 | 78 | $value = $response->getHeaderLine($shape['locationName'] ?: $name); |
| 79 | + // Empty headers should not be deserialized | |
| 80 | + if ($value === null || $value === '') { | |
| 81 | + return; | |
| 82 | + } | |
| 75 | 83 | switch ($shape->getType()) { |
| 76 | 84 | case 'float': |
| 77 | 85 | case 'double': |
| 78 | - $value = (float) $value; | |
| 86 | + $value = match ($value) { | |
| 87 | + 'NaN', 'Infinity', '-Infinity' => $value, | |
| 88 | + default => (float) $value, | |
| 89 | + }; | |
| 79 | 90 | break; |
| 80 | 91 | case 'long': |
| 92 | + case 'integer': | |
| 81 | 93 | $value = (int) $value; |
| 82 | 94 | break; |
| 83 | 95 | case 'boolean': |
| 84 | 96 | $value = \filter_var($value, \FILTER_VALIDATE_BOOLEAN); |
| @@ -109,8 +121,19 @@ | ||
| 109 | 121 | //If the value cannot be parsed, then do not add it to the |
| 110 | 122 | //output structure. |
| 111 | 123 | return; |
| 112 | 124 | } |
| 125 | + case 'list': | |
| 126 | + $listMember = $shape->getMember(); | |
| 127 | + $type = $listMember->getType(); | |
| 128 | + // Only boolean lists require special handling | |
| 129 | + // other types can be returned as-is | |
| 130 | + if ($type !== 'boolean') { | |
| 131 | + break; | |
| 132 | + } | |
| 133 | + $items = \array_map('trim', \explode(',', $value)); | |
| 134 | + $value = \array_map(static fn($item) => \filter_var($item, \FILTER_VALIDATE_BOOLEAN), $items); | |
| 135 | + break; | |
| 113 | 136 | } |
| 114 | 137 | $result[$name] = $value; |
| 115 | 138 | } |
| 116 | 139 | /** |