| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Api; |
| 4 |
|
| 5 |
/** |
| 6 |
* Base class that is used by most API shapes |
| 7 |
*/ |
| 8 |
abstract class AbstractModel implements \ArrayAccess |
| 9 |
{ |
| 10 |
/** @var array */ |
| 11 |
protected $definition; |
| 12 |
/** @var ShapeMap */ |
| 13 |
protected $shapeMap; |
| 14 |
/** |
| 15 |
* @param array $definition Service description |
| 16 |
* @param ShapeMap $shapeMap Shapemap used for creating shapes |
| 17 |
*/ |
| 18 |
public function __construct(array $definition, ShapeMap $shapeMap) |
| 19 |
{ |
| 20 |
$this->definition = $definition; |
| 21 |
$this->shapeMap = $shapeMap; |
| 22 |
} |
| 23 |
public function toArray() |
| 24 |
{ |
| 25 |
return $this->definition; |
| 26 |
} |
| 27 |
/** |
| 28 |
* @return mixed|null |
| 29 |
*/ |
| 30 |
#[\ReturnTypeWillChange] |
| 31 |
public function offsetGet($offset) |
| 32 |
{ |
| 33 |
return isset($this->definition[$offset]) ? $this->definition[$offset] : null; |
| 34 |
} |
| 35 |
/** |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
#[\ReturnTypeWillChange] |
| 39 |
public function offsetSet($offset, $value) |
| 40 |
{ |
| 41 |
$this->definition[$offset] = $value; |
| 42 |
} |
| 43 |
/** |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
#[\ReturnTypeWillChange] |
| 47 |
public function offsetExists($offset) |
| 48 |
{ |
| 49 |
return isset($this->definition[$offset]); |
| 50 |
} |
| 51 |
/** |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
#[\ReturnTypeWillChange] |
| 55 |
public function offsetUnset($offset) |
| 56 |
{ |
| 57 |
unset($this->definition[$offset]); |
| 58 |
} |
| 59 |
protected function shapeAt($key) |
| 60 |
{ |
| 61 |
if (!isset($this->definition[$key])) { |
| 62 |
throw new \InvalidArgumentException('Expected shape definition at ' . $key); |
| 63 |
} |
| 64 |
return $this->shapeFor($this->definition[$key]); |
| 65 |
} |
| 66 |
protected function shapeFor(array $definition) |
| 67 |
{ |
| 68 |
return isset($definition['shape']) ? $this->shapeMap->resolve($definition) : Shape::create($definition, $this->shapeMap); |
| 69 |
} |
| 70 |
} |
| 71 |
|