Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Parser/JsonParser.php

raw symbols SCIP
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 // null map values should not be deserialized
54 if (!is_null($v)) {
55 $target[$k] = $this->parse($values, $v);
56 }
57 }
58 return $target;
59
60 case 'timestamp':
61 return DateTimeResult::fromTimestamp(
62 $value,
63 !empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null
64 );
65
66 case 'blob':
67 return base64_decode($value);
68
69 default:
70 return $value;
71 }
72 }
73 }
74