Shape.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Aws\Api;
  3. /**
  4. * Base class representing a modeled shape.
  5. */
  6. class Shape extends AbstractModel
  7. {
  8. /**
  9. * Get a concrete shape for the given definition.
  10. *
  11. * @param array $definition
  12. * @param ShapeMap $shapeMap
  13. *
  14. * @return mixed
  15. * @throws \RuntimeException if the type is invalid
  16. */
  17. public static function create(array $definition, ShapeMap $shapeMap)
  18. {
  19. static $map = [
  20. 'structure' => 'Aws\Api\StructureShape',
  21. 'map' => 'Aws\Api\MapShape',
  22. 'list' => 'Aws\Api\ListShape',
  23. 'timestamp' => 'Aws\Api\TimestampShape',
  24. 'integer' => 'Aws\Api\Shape',
  25. 'double' => 'Aws\Api\Shape',
  26. 'float' => 'Aws\Api\Shape',
  27. 'long' => 'Aws\Api\Shape',
  28. 'string' => 'Aws\Api\Shape',
  29. 'byte' => 'Aws\Api\Shape',
  30. 'character' => 'Aws\Api\Shape',
  31. 'blob' => 'Aws\Api\Shape',
  32. 'boolean' => 'Aws\Api\Shape'
  33. ];
  34. if (isset($definition['shape'])) {
  35. return $shapeMap->resolve($definition);
  36. }
  37. if (!isset($map[$definition['type']])) {
  38. throw new \RuntimeException('Invalid type: '
  39. . print_r($definition, true));
  40. }
  41. $type = $map[$definition['type']];
  42. return new $type($definition, $shapeMap);
  43. }
  44. /**
  45. * Get the type of the shape
  46. *
  47. * @return string
  48. */
  49. public function getType()
  50. {
  51. return $this->definition['type'];
  52. }
  53. /**
  54. * Get the name of the shape
  55. *
  56. * @return string
  57. */
  58. public function getName()
  59. {
  60. return $this->definition['name'];
  61. }
  62. }