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