Debian Codegraph @

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

raw symbols SCIP
1 <?php
2 namespace Aws\Api;
3
4 /**
5 * Builds shape based on shape references.
6 */
7 class ShapeMap implements \ArrayAccess
8 {
9 /** @var array */
10 private $definitions;
11
12 /** @var Shape[] */
13 private $simple;
14
15 /**
16 * @param array $shapeModels Associative array of shape definitions.
17 */
18 public function __construct(array $shapeModels)
19 {
20 $this->definitions = $shapeModels;
21 }
22
23 /**
24 * Get an array of shape names.
25 *
26 * @return array
27 */
28 public function getShapeNames()
29 {
30 return array_keys($this->definitions);
31 }
32
33 /**
34 * Resolve a shape reference
35 *
36 * @param array $shapeRef Shape reference shape
37 *
38 * @return Shape
39 * @throws \InvalidArgumentException
40 */
41 public function resolve(array $shapeRef)
42 {
43 $shape = $shapeRef['shape'];
44
45 if (!isset($this->definitions[$shape])) {
46 throw new \InvalidArgumentException('Shape not found: ' . $shape);
47 }
48
49 $isSimple = count($shapeRef) == 1;
50 if ($isSimple && isset($this->simple[$shape])) {
51 return $this->simple[$shape];
52 }
53
54 $shapeDefinition = $this->definitions[$shape];
55 $definition = $shapeRef + $shapeDefinition;
56 // Property to know whether the locationName was set at member level
57 // or the structure level.
58 if (isset($shapeDefinition['locationName'])) {
59 $definition['locationNameAtStructureLevel'] = true;
60 }
61
62 $definition['name'] = $definition['shape'];
63 if (isset($definition['shape'])) {
64 unset($definition['shape']);
65 }
66
67 $result = Shape::create($definition, $this);
68
69 if ($isSimple) {
70 $this->simple[$shape] = $result;
71 }
72
73 return $result;
74 }
75
76 /**
77 * @param mixed $offset
78 * @return bool
79 */
80 public function offsetExists(mixed $offset): bool
81 {
82 return isset($this->definitions[$offset]);
83 }
84
85 /**
86 * @param mixed $offset
87 * @return mixed
88 */
89 public function offsetGet(mixed $offset): mixed
90 {
91 return $this->definitions[$offset] ?? null;
92 }
93
94 /**
95 * @param mixed $offset
96 * @param mixed $value
97 * @throws \BadMethodCallException
98 */
99 public function offsetSet(mixed $offset, mixed $value): void
100 {
101 throw new \BadMethodCallException(
102 'ShapeMap is read-only and cannot be modified.'
103 );
104 }
105
106 /**
107 * @param mixed $offset
108 * @throws \BadMethodCallException
109 */
110 public function offsetUnset(mixed $offset): void
111 {
112 throw new \BadMethodCallException(
113 'ShapeMap is read-only and cannot be modified.'
114 );
115 }
116 }