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
JsonParser.php
72 lines
| 1 | <?php |
| 2 | namespace Aws\Api\Parser; |
| 3 | |
| 4 | use Aws\Api\DateTimeResult; |
| 5 | use Aws\Api\Shape; |
| 6 | |
| 7 | /** |
| 8 | * @internal Implements standard JSON parsing. |
| 9 | */ |
| 10 | class JsonParser |
| 11 | { |
| 12 | public function parse(Shape $shape, $value) |
| 13 | { |
| 14 | if ($value === null) { |
| 15 | return $value; |
| 16 | } |
| 17 | |
| 18 | switch ($shape['type']) { |
| 19 | case 'structure': |
| 20 | if (isset($shape['document']) && $shape['document']) { |
| 21 | return $value; |
| 22 | } |
| 23 | $target = []; |
| 24 | foreach ($shape->getMembers() as $name => $member) { |
| 25 | $locationName = $member['locationName'] ?: $name; |
| 26 | if (isset($value[$locationName])) { |
| 27 | $target[$name] = $this->parse($member, $value[$locationName]); |
| 28 | } |
| 29 | } |
| 30 | if (isset($shape['union']) |
| 31 | && $shape['union'] |
| 32 | && is_array($value) |
| 33 | && empty($target) |
| 34 | ) { |
| 35 | foreach ($value as $key => $val) { |
| 36 | $target['Unknown'][$key] = $val; |
| 37 | } |
| 38 | } |
| 39 | return $target; |
| 40 | |
| 41 | case 'list': |
| 42 | $member = $shape->getMember(); |
| 43 | $target = []; |
| 44 | foreach ($value as $v) { |
| 45 | $target[] = $this->parse($member, $v); |
| 46 | } |
| 47 | return $target; |
| 48 | |
| 49 | case 'map': |
| 50 | $values = $shape->getValue(); |
| 51 | $target = []; |
| 52 | foreach ($value as $k => $v) { |
| 53 | $target[$k] = $this->parse($values, $v); |
| 54 | } |
| 55 | return $target; |
| 56 | |
| 57 | case 'timestamp': |
| 58 | return DateTimeResult::fromTimestamp( |
| 59 | $value, |
| 60 | !empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null |
| 61 | ); |
| 62 | |
| 63 | case 'blob': |
| 64 | return base64_decode($value); |
| 65 | |
| 66 | default: |
| 67 | return $value; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 |