| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Api; |
| 4 |
|
| 5 |
/** |
| 6 |
* Represents a structure shape and resolve member shape references. |
| 7 |
*/ |
| 8 |
class StructureShape extends Shape |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @var Shape[] |
| 12 |
*/ |
| 13 |
private $members; |
| 14 |
public function __construct(array $definition, ShapeMap $shapeMap) |
| 15 |
{ |
| 16 |
$definition['type'] = 'structure'; |
| 17 |
if (!isset($definition['members'])) { |
| 18 |
$definition['members'] = []; |
| 19 |
} |
| 20 |
parent::__construct($definition, $shapeMap); |
| 21 |
} |
| 22 |
/** |
| 23 |
* Gets a list of all members |
| 24 |
* |
| 25 |
* @return Shape[] |
| 26 |
*/ |
| 27 |
public function getMembers() |
| 28 |
{ |
| 29 |
if (empty($this->members)) { |
| 30 |
$this->generateMembersHash(); |
| 31 |
} |
| 32 |
return $this->members; |
| 33 |
} |
| 34 |
/** |
| 35 |
* Check if a specific member exists by name. |
| 36 |
* |
| 37 |
* @param string $name Name of the member to check |
| 38 |
* |
| 39 |
* @return bool |
| 40 |
*/ |
| 41 |
public function hasMember($name) |
| 42 |
{ |
| 43 |
return isset($this->definition['members'][$name]); |
| 44 |
} |
| 45 |
/** |
| 46 |
* Retrieve a member by name. |
| 47 |
* |
| 48 |
* @param string $name Name of the member to retrieve |
| 49 |
* |
| 50 |
* @return Shape |
| 51 |
* @throws \InvalidArgumentException if the member is not found. |
| 52 |
*/ |
| 53 |
public function getMember($name) |
| 54 |
{ |
| 55 |
$members = $this->getMembers(); |
| 56 |
if (!isset($members[$name])) { |
| 57 |
throw new \InvalidArgumentException('Unknown member ' . $name); |
| 58 |
} |
| 59 |
return $members[$name]; |
| 60 |
} |
| 61 |
/** |
| 62 |
* Used to look up the shape's original definition. |
| 63 |
* ShapeMap::resolve() merges properties from both |
| 64 |
* member and target shape definitions, causing certain |
| 65 |
* properties like `locationName` to be overwritten. |
| 66 |
* |
| 67 |
* @return ShapeMap |
| 68 |
* @internal This method is for internal use only and should not be used |
| 69 |
* by external code. It may be changed or removed without notice. |
| 70 |
*/ |
| 71 |
public function getShapeMap() : ShapeMap |
| 72 |
{ |
| 73 |
return $this->shapeMap; |
| 74 |
} |
| 75 |
/** |
| 76 |
* Used to look up a shape's original definition. |
| 77 |
* |
| 78 |
* @param string $name |
| 79 |
* |
| 80 |
* @return array|null |
| 81 |
*/ |
| 82 |
public function getOriginalDefinition(string $name) : ?array |
| 83 |
{ |
| 84 |
return $this->shapeMap[$name] ?? null; |
| 85 |
} |
| 86 |
private function generateMembersHash() |
| 87 |
{ |
| 88 |
$this->members = []; |
| 89 |
foreach ($this->definition['members'] as $name => $definition) { |
| 90 |
$this->members[$name] = $this->shapeFor($definition); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|