Image.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Rackspace
  17. * @subpackage Servers
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Service/Rackspace/Servers.php';
  22. class Zend_Service_Rackspace_Servers_Image
  23. {
  24. const ERROR_PARAM_CONSTRUCT = 'You must pass a Zend_Service_Rackspace_Servers object and an array';
  25. const ERROR_PARAM_NO_NAME = 'You must pass the image\'s name in the array (name)';
  26. const ERROR_PARAM_NO_ID = 'You must pass the image\'s id in the array (id)';
  27. /**
  28. * Name of the image
  29. *
  30. * @var string
  31. */
  32. protected $name;
  33. /**
  34. * Id of the image
  35. *
  36. * @var string
  37. */
  38. protected $id;
  39. /**
  40. * Server Id of the image
  41. *
  42. * @var string
  43. */
  44. protected $serverId;
  45. /**
  46. * Updated data
  47. *
  48. * @var string
  49. */
  50. protected $updated;
  51. /**
  52. * Created data
  53. *
  54. * @var string
  55. */
  56. protected $created;
  57. /**
  58. * Status
  59. *
  60. * @var string
  61. */
  62. protected $status;
  63. /**
  64. * Status progress
  65. *
  66. * @var integer
  67. */
  68. protected $progress;
  69. /**
  70. * The service that has created the image object
  71. *
  72. * @var Zend_Service_Rackspace_Servers
  73. */
  74. protected $service;
  75. /**
  76. * Construct
  77. *
  78. * @param array $data
  79. * @return void
  80. */
  81. public function __construct($service, $data)
  82. {
  83. if (!($service instanceof Zend_Service_Rackspace_Servers) || !is_array($data)) {
  84. require_once 'Zend/Service/Rackspace/Servers/Exception.php';
  85. throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_CONSTRUCT);
  86. }
  87. if (!array_key_exists('name', $data)) {
  88. require_once 'Zend/Service/Rackspace/Servers/Exception.php';
  89. throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_NAME);
  90. }
  91. if (!array_key_exists('id', $data)) {
  92. require_once 'Zend/Service/Rackspace/Servers/Exception.php';
  93. throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_ID);
  94. }
  95. $this->service= $service;
  96. $this->name = $data['name'];
  97. $this->id = $data['id'];
  98. if (isset($data['serverId'])) {
  99. $this->serverId= $data['serverId'];
  100. }
  101. if (isset($data['updated'])) {
  102. $this->updated= $data['updated'];
  103. }
  104. if (isset($data['created'])) {
  105. $this->created= $data['created'];
  106. }
  107. if (isset($data['status'])) {
  108. $this->status= $data['status'];
  109. }
  110. if (isset($data['progress'])) {
  111. $this->progress= $data['progress'];
  112. }
  113. }
  114. /**
  115. * Get the name of the image
  116. *
  117. * @return string
  118. */
  119. public function getName()
  120. {
  121. return $this->name;
  122. }
  123. /**
  124. * Get the image's id
  125. *
  126. * @return string
  127. */
  128. public function getId()
  129. {
  130. return $this->id;
  131. }
  132. /**
  133. * Get the server's id of the image
  134. *
  135. * @return string
  136. */
  137. public function getServerId()
  138. {
  139. return $this->serverId;
  140. }
  141. /**
  142. * Get the updated data
  143. *
  144. * @return string
  145. */
  146. public function getUpdated()
  147. {
  148. return $this->updated;
  149. }
  150. /**
  151. * Get the created data
  152. *
  153. * @return string
  154. */
  155. public function getCreated()
  156. {
  157. return $this->created;
  158. }
  159. /**
  160. * Get the image's status
  161. *
  162. * @return string|boolean
  163. */
  164. public function getStatus()
  165. {
  166. $data= $this->service->getImage($this->id);
  167. if ($data!==false) {
  168. $data= $data->toArray();
  169. $this->status= $data['status'];
  170. return $this->status;
  171. }
  172. return false;
  173. }
  174. /**
  175. * Get the progress's status
  176. *
  177. * @return integer|boolean
  178. */
  179. public function getProgress()
  180. {
  181. $data= $this->service->getImage($this->id);
  182. if ($data!==false) {
  183. $data= $data->toArray();
  184. $this->progress= $data['progress'];
  185. return $this->progress;
  186. }
  187. return false;
  188. }
  189. /**
  190. * To Array
  191. *
  192. * @return array
  193. */
  194. public function toArray()
  195. {
  196. return array (
  197. 'name' => $this->name,
  198. 'id' => $this->id,
  199. 'serverId' => $this->serverId,
  200. 'updated' => $this->updated,
  201. 'created' => $this->created,
  202. 'status' => $this->status,
  203. 'progress' => $this->progress
  204. );
  205. }
  206. }