PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / ShapeMap.php

ShapeMap.php in Media Cloud Sync 1.4.2, at includes/sdk/s3/Aws/Api/ShapeMap.php

93 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Api;
4
5 /**
6 * Builds shape based on shape references.
7 */
8 class ShapeMap implements \ArrayAccess
9 {
10 /** @var array */
11 private $definitions;
12 /** @var Shape[] */
13 private $simple;
14 /**
15 * @param array $shapeModels Associative array of shape definitions.
16 */
17 public function __construct(array $shapeModels)
18 {
19 $this->definitions = $shapeModels;
20 }
21 /**
22 * Get an array of shape names.
23 *
24 * @return array
25 */
26 public function getShapeNames()
27 {
28 return \array_keys($this->definitions);
29 }
30 /**
31 * Resolve a shape reference
32 *
33 * @param array $shapeRef Shape reference shape
34 *
35 * @return Shape
36 * @throws \InvalidArgumentException
37 */
38 public function resolve(array $shapeRef)
39 {
40 $shape = $shapeRef['shape'];
41 if (!isset($this->definitions[$shape])) {
42 throw new \InvalidArgumentException('Shape not found: ' . $shape);
43 }
44 $isSimple = \count($shapeRef) == 1;
45 if ($isSimple && isset($this->simple[$shape])) {
46 return $this->simple[$shape];
47 }
48 $definition = $shapeRef + $this->definitions[$shape];
49 $definition['name'] = $definition['shape'];
50 if (isset($definition['shape'])) {
51 unset($definition['shape']);
52 }
53 $result = Shape::create($definition, $this);
54 if ($isSimple) {
55 $this->simple[$shape] = $result;
56 }
57 return $result;
58 }
59 /**
60 * @param mixed $offset
61 * @return bool
62 */
63 public function offsetExists(mixed $offset) : bool
64 {
65 return isset($this->definitions[$offset]);
66 }
67 /**
68 * @param mixed $offset
69 * @return mixed
70 */
71 public function offsetGet(mixed $offset) : mixed
72 {
73 return $this->definitions[$offset] ?? null;
74 }
75 /**
76 * @param mixed $offset
77 * @param mixed $value
78 * @throws \BadMethodCallException
79 */
80 public function offsetSet(mixed $offset, mixed $value) : void
81 {
82 throw new \BadMethodCallException('ShapeMap is read-only and cannot be modified.');
83 }
84 /**
85 * @param mixed $offset
86 * @throws \BadMethodCallException
87 */
88 public function offsetUnset(mixed $offset) : void
89 {
90 throw new \BadMethodCallException('ShapeMap is read-only and cannot be modified.');
91 }
92 }
93