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