PluginProbe
Media Cloud Sync / 1.0.2
Media Cloud Sync v1.0.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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / ShapeMap.php

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

60 lines 1.5 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
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