← All changes
|
includes/sdk/s3/Aws/Api/Parser/EventParsingIterator.php
+24
-0
1.2.13
→
1.4.2
View file →
| @@ -40,28 +40,43 @@ | ||
| 40 | 40 | } else { |
| 41 | 41 | return new NonSeekableStreamDecodingEventStreamIterator($stream); |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | + /** | |
| 45 | + * @return mixed | |
| 46 | + */ | |
| 44 | 47 | #[\ReturnTypeWillChange] |
| 45 | 48 | public function current() |
| 46 | 49 | { |
| 47 | 50 | return $this->parseEvent($this->decodingIterator->current()); |
| 48 | 51 | } |
| 52 | + /** | |
| 53 | + * @return mixed | |
| 54 | + */ | |
| 49 | 55 | #[\ReturnTypeWillChange] |
| 50 | 56 | public function key() |
| 51 | 57 | { |
| 52 | 58 | return $this->decodingIterator->key(); |
| 53 | 59 | } |
| 60 | + /** | |
| 61 | + * @return void | |
| 62 | + */ | |
| 54 | 63 | #[\ReturnTypeWillChange] |
| 55 | 64 | public function next() |
| 56 | 65 | { |
| 57 | 66 | $this->decodingIterator->next(); |
| 58 | 67 | } |
| 68 | + /** | |
| 69 | + * @return void | |
| 70 | + */ | |
| 59 | 71 | #[\ReturnTypeWillChange] |
| 60 | 72 | public function rewind() |
| 61 | 73 | { |
| 62 | 74 | $this->decodingIterator->rewind(); |
| 63 | 75 | } |
| 76 | + /** | |
| 77 | + * @return bool | |
| 78 | + */ | |
| 64 | 79 | #[\ReturnTypeWillChange] |
| 65 | 80 | public function valid() |
| 66 | 81 | { |
| 67 | 82 | return $this->decodingIterator->valid(); |
| @@ -71,8 +86,11 @@ | ||
| 71 | 86 | if (!empty($event['headers'][':message-type'])) { |
| 72 | 87 | if ($event['headers'][':message-type'] === 'error') { |
| 73 | 88 | return $this->parseError($event); |
| 74 | 89 | } |
| 90 | + if ($event['headers'][':message-type'] === 'exception') { | |
| 91 | + return $this->parseException($event); | |
| 92 | + } | |
| 75 | 93 | if ($event['headers'][':message-type'] !== 'event') { |
| 76 | 94 | throw new ParserException('Failed to parse unknown message type.'); |
| 77 | 95 | } |
| 78 | 96 | } |
| @@ -134,8 +152,14 @@ | ||
| 134 | 152 | } |
| 135 | 153 | private function parseError(array $event) |
| 136 | 154 | { |
| 137 | 155 | throw new EventStreamDataException($event['headers'][':error-code'], $event['headers'][':error-message']); |
| 156 | + } | |
| 157 | + private function parseException(array $event) | |
| 158 | + { | |
| 159 | + $payload = $event['payload']?->getContents(); | |
| 160 | + $parsedPayload = \json_decode($payload, \true); | |
| 161 | + throw new EventStreamDataException($event['headers'][':exception-type'] ?? 'Unknown', $parsedPayload['message'] ?? $payload); | |
| 138 | 162 | } |
| 139 | 163 | private function parseInitialResponseEvent($payload) : array |
| 140 | 164 | { |
| 141 | 165 | return ['initial-response' => \json_decode($payload, \true)]; |