Image.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * @category Zend
  4. * @package Zend_Cloud
  5. * @subpackage Infrastructure
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. /**
  10. * Instance of an infrastructure service
  11. *
  12. * @package Zend_Cloud
  13. * @subpackage Infrastructure
  14. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  15. * @license http://framework.zend.com/license/new-bsd New BSD License
  16. */
  17. class Zend_Cloud_Infrastructure_Image
  18. {
  19. const IMAGE_ID = 'imageId';
  20. const IMAGE_OWNERID = 'ownerId';
  21. const IMAGE_NAME = 'name';
  22. const IMAGE_DESCRIPTION = 'description';
  23. const IMAGE_PLATFORM = 'platform';
  24. const IMAGE_ARCHITECTURE = 'architecture';
  25. const ARCH_32BIT = 'i386';
  26. const ARCH_64BIT = 'x86_64';
  27. const IMAGE_WINDOWS = 'windows';
  28. const IMAGE_LINUX = 'linux';
  29. /**
  30. * Image's attributes
  31. *
  32. * @var array
  33. */
  34. protected $attributes = array();
  35. /**
  36. * The Image adapter (if exists)
  37. *
  38. * @var object
  39. */
  40. protected $adapter;
  41. /**
  42. * Required attributes
  43. *
  44. * @var array
  45. */
  46. protected $attributeRequired = array(
  47. self::IMAGE_ID,
  48. self::IMAGE_DESCRIPTION,
  49. self::IMAGE_PLATFORM,
  50. self::IMAGE_ARCHITECTURE,
  51. );
  52. /**
  53. * Constructor
  54. *
  55. * @param array $data
  56. * @param object $adapter
  57. */
  58. public function __construct($data, $adapter = null)
  59. {
  60. if (is_object($data)) {
  61. if (method_exists($data, 'toArray')) {
  62. $data= $data->toArray();
  63. } elseif ($data instanceof Traversable) {
  64. $data = iterator_to_array($data);
  65. }
  66. }
  67. if (empty($data) || !is_array($data)) {
  68. require_once 'Zend/Cloud/Infrastructure/Exception.php';
  69. throw new Zend_Cloud_Infrastructure_Exception('You must pass an array of parameters');
  70. }
  71. foreach ($this->attributeRequired as $key) {
  72. if (empty($data[$key])) {
  73. require_once 'Zend/Cloud/Infrastructure/Exception.php';
  74. throw new Zend_Cloud_Infrastructure_Exception(sprintf(
  75. 'The param "%s" is a required parameter for class %s',
  76. $key,
  77. __CLASS__
  78. ));
  79. }
  80. }
  81. $this->attributes = $data;
  82. $this->adapter = $adapter;
  83. }
  84. /**
  85. * Get Attribute with a specific key
  86. *
  87. * @param array $data
  88. * @return misc|boolean
  89. */
  90. public function getAttribute($key)
  91. {
  92. if (!empty($this->attributes[$key])) {
  93. return $this->attributes[$key];
  94. }
  95. return false;
  96. }
  97. /**
  98. * Get all the attributes
  99. *
  100. * @return array
  101. */
  102. public function getAttributes()
  103. {
  104. return $this->attributes;
  105. }
  106. /**
  107. * Get the image ID
  108. *
  109. * @return string
  110. */
  111. public function getId()
  112. {
  113. return $this->attributes[self::IMAGE_ID];
  114. }
  115. /**
  116. * Get the Owner ID
  117. *
  118. * @return string
  119. */
  120. public function getOwnerId()
  121. {
  122. return $this->attributes[self::IMAGE_OWNERID];
  123. }
  124. /**
  125. * Get the name
  126. *
  127. * @return string
  128. */
  129. public function getName()
  130. {
  131. return $this->attributes[self::IMAGE_NAME];
  132. }
  133. /**
  134. * Get the description
  135. *
  136. * @return string
  137. */
  138. public function getDescription()
  139. {
  140. return $this->attributes[self::IMAGE_DESCRIPTION];
  141. }
  142. /**
  143. * Get the platform
  144. *
  145. * @return string
  146. */
  147. public function getPlatform()
  148. {
  149. return $this->attributes[self::IMAGE_PLATFORM];
  150. }
  151. /**
  152. * Get the architecture
  153. *
  154. * @return string
  155. */
  156. public function getArchitecture()
  157. {
  158. return $this->attributes[self::IMAGE_ARCHITECTURE];
  159. }
  160. }