| 1 |
<?php |
| 2 |
namespace Aws\Api; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class ShapeMap implements \ArrayAccess |
| 8 |
{ |
| 9 |
|
| 10 |
private $definitions; |
| 11 |
|
| 12 |
|
| 13 |
private $simple; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public function __construct(array $shapeModels) |
| 19 |
{ |
| 20 |
$this->definitions = $shapeModels; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function getShapeNames() |
| 29 |
{ |
| 30 |
return array_keys($this->definitions); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 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 |
|
| 57 |
|
| 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 |
|
| 78 |
|
| 79 |
|
| 80 |
public function offsetExists(mixed $offset): bool |
| 81 |
{ |
| 82 |
return isset($this->definitions[$offset]); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public function offsetGet(mixed $offset): mixed |
| 90 |
{ |
| 91 |
return $this->definitions[$offset] ?? null; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 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 |
|
| 108 |
|
| 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 |
} |