ErrorParser
11 months ago
Parser
11 months ago
Serializer
11 months ago
AbstractModel.php
11 months ago
ApiProvider.php
11 months ago
DateTimeResult.php
11 months ago
DocModel.php
11 months ago
ListShape.php
11 months ago
MapShape.php
11 months ago
Operation.php
11 months ago
Service.php
11 months ago
Shape.php
11 months ago
ShapeMap.php
11 months ago
StructureShape.php
11 months ago
TimestampShape.php
11 months ago
Validator.php
11 months ago
StructureShape.php
80 lines
| 1 | <?php |
| 2 | namespace Aws\Api; |
| 3 | |
| 4 | /** |
| 5 | * Represents a structure shape and resolve member shape references. |
| 6 | */ |
| 7 | class StructureShape extends Shape |
| 8 | { |
| 9 | /** |
| 10 | * @var Shape[] |
| 11 | */ |
| 12 | private $members; |
| 13 | |
| 14 | public function __construct(array $definition, ShapeMap $shapeMap) |
| 15 | { |
| 16 | $definition['type'] = 'structure'; |
| 17 | |
| 18 | if (!isset($definition['members'])) { |
| 19 | $definition['members'] = []; |
| 20 | } |
| 21 | |
| 22 | parent::__construct($definition, $shapeMap); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Gets a list of all members |
| 27 | * |
| 28 | * @return Shape[] |
| 29 | */ |
| 30 | public function getMembers() |
| 31 | { |
| 32 | if (empty($this->members)) { |
| 33 | $this->generateMembersHash(); |
| 34 | } |
| 35 | |
| 36 | return $this->members; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Check if a specific member exists by name. |
| 41 | * |
| 42 | * @param string $name Name of the member to check |
| 43 | * |
| 44 | * @return bool |
| 45 | */ |
| 46 | public function hasMember($name) |
| 47 | { |
| 48 | return isset($this->definition['members'][$name]); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Retrieve a member by name. |
| 53 | * |
| 54 | * @param string $name Name of the member to retrieve |
| 55 | * |
| 56 | * @return Shape |
| 57 | * @throws \InvalidArgumentException if the member is not found. |
| 58 | */ |
| 59 | public function getMember($name) |
| 60 | { |
| 61 | $members = $this->getMembers(); |
| 62 | |
| 63 | if (!isset($members[$name])) { |
| 64 | throw new \InvalidArgumentException('Unknown member ' . $name); |
| 65 | } |
| 66 | |
| 67 | return $members[$name]; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | private function generateMembersHash() |
| 72 | { |
| 73 | $this->members = []; |
| 74 | |
| 75 | foreach ($this->definition['members'] as $name => $definition) { |
| 76 | $this->members[$name] = $this->shapeFor($definition); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 |