14 * to license@zend.com so we can send you a copy immediately. |
14 * to license@zend.com so we can send you a copy immediately. |
15 * |
15 * |
16 * @category Zend |
16 * @category Zend |
17 * @package Zend_Service_Rackspace |
17 * @package Zend_Service_Rackspace |
18 * @subpackage Files |
18 * @subpackage Files |
19 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
21 */ |
21 */ |
22 |
22 |
23 require_once 'Zend/Service/Rackspace/Files.php'; |
23 require_once 'Zend/Service/Rackspace/Files.php'; |
24 |
24 |
25 class Zend_Service_Rackspace_Files_Container |
25 class Zend_Service_Rackspace_Files_Container |
26 { |
26 { |
27 const ERROR_PARAM_FILE_CONSTRUCT = 'The Zend_Service_Rackspace_Files passed in construction is not valid'; |
27 const ERROR_PARAM_FILE_CONSTRUCT = 'The Zend_Service_Rackspace_Files passed in construction is not valid'; |
|
28 |
28 const ERROR_PARAM_ARRAY_CONSTRUCT = 'The array passed in construction is not valid'; |
29 const ERROR_PARAM_ARRAY_CONSTRUCT = 'The array passed in construction is not valid'; |
29 const ERROR_PARAM_NO_NAME = 'The container name is empty'; |
30 |
|
31 const ERROR_PARAM_NO_NAME = 'The container name is empty'; |
|
32 |
30 /** |
33 /** |
31 * @var string |
34 * @var string |
32 */ |
35 */ |
33 protected $name; |
36 protected $name; |
|
37 |
34 /** |
38 /** |
35 * Construct |
39 * Construct |
36 * |
40 * |
37 * @param Zend_Service_Rackspace_Files $service |
41 * @param Zend_Service_Rackspace_Files $service |
38 * @param string $name |
42 * @param $data |
|
43 * |
|
44 * @throws Zend_Service_Rackspace_Files_Exception |
39 */ |
45 */ |
40 public function __construct($service, $data) |
46 public function __construct($service, $data) |
41 { |
47 { |
42 if (!($service instanceof Zend_Service_Rackspace_Files)) { |
48 if (!($service instanceof Zend_Service_Rackspace_Files)) { |
43 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
49 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
44 throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_FILE_CONSTRUCT); |
50 throw new Zend_Service_Rackspace_Files_Exception( |
|
51 self::ERROR_PARAM_FILE_CONSTRUCT |
|
52 ); |
45 } |
53 } |
46 if (!is_array($data)) { |
54 if (!is_array($data)) { |
47 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
55 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
48 throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_ARRAY_CONSTRUCT); |
56 throw new Zend_Service_Rackspace_Files_Exception( |
|
57 self::ERROR_PARAM_ARRAY_CONSTRUCT |
|
58 ); |
49 } |
59 } |
50 if (!array_key_exists('name', $data)) { |
60 if (!array_key_exists('name', $data)) { |
51 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
61 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
52 throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_NO_NAME); |
62 throw new Zend_Service_Rackspace_Files_Exception( |
53 } |
63 self::ERROR_PARAM_NO_NAME |
|
64 ); |
|
65 } |
54 $this->service = $service; |
66 $this->service = $service; |
55 $this->name = $data['name']; |
67 $this->name = $data['name']; |
56 } |
68 } |
|
69 |
57 /** |
70 /** |
58 * Get the name of the container |
71 * Get the name of the container |
59 * |
72 * |
60 * @return string |
73 * @return string |
61 */ |
74 */ |
62 public function getName() |
75 public function getName() |
63 { |
76 { |
64 return $this->name; |
77 return $this->name; |
65 } |
78 } |
|
79 |
66 /** |
80 /** |
67 * Get the size in bytes of the container |
81 * Get the size in bytes of the container |
68 * |
82 * |
69 * @return integer|boolean |
83 * @return integer|bool |
70 */ |
84 */ |
71 public function getSize() |
85 public function getSize() |
72 { |
86 { |
73 $data = $this->getInfo(); |
87 $data = $this->getInfo(); |
74 if (isset($data['bytes'])) { |
88 if (isset($data['bytes'])) { |
75 return $data['bytes']; |
89 return $data['bytes']; |
76 } |
90 } |
77 return false; |
91 |
78 } |
92 return false; |
|
93 } |
|
94 |
79 /** |
95 /** |
80 * Get the total count of objects in the container |
96 * Get the total count of objects in the container |
81 * |
97 * |
82 * @return integer|boolean |
98 * @return integer|bool |
83 */ |
99 */ |
84 public function getObjectCount() |
100 public function getObjectCount() |
85 { |
101 { |
86 $data = $this->getInfo(); |
102 $data = $this->getInfo(); |
87 if (isset($data['count'])) { |
103 if (isset($data['count'])) { |
88 return $data['count']; |
104 return $data['count']; |
89 } |
105 } |
90 return false; |
106 |
91 } |
107 return false; |
|
108 } |
|
109 |
92 /** |
110 /** |
93 * Return true if the container is CDN enabled |
111 * Return true if the container is CDN enabled |
94 * |
112 * |
95 * @return boolean |
113 * @return bool |
96 */ |
114 */ |
97 public function isCdnEnabled() |
115 public function isCdnEnabled() |
98 { |
116 { |
99 $data = $this->getCdnInfo(); |
117 $data = $this->getCdnInfo(); |
100 if (isset($data['cdn_enabled'])) { |
118 if (isset($data['cdn_enabled'])) { |
101 return $data['cdn_enabled']; |
119 return $data['cdn_enabled']; |
102 } |
120 } |
103 return false; |
121 |
104 } |
122 return false; |
|
123 } |
|
124 |
105 /** |
125 /** |
106 * Get the TTL of the CDN |
126 * Get the TTL of the CDN |
107 * |
127 * |
108 * @return integer|boolean |
128 * @return integer|bool |
109 */ |
129 */ |
110 public function getCdnTtl() |
130 public function getCdnTtl() |
111 { |
131 { |
112 $data = $this->getCdnInfo(); |
132 $data = $this->getCdnInfo(); |
113 if (!isset($data['ttl'])) { |
133 if (isset($data['ttl'])) { |
114 return $data['ttl']; |
134 return $data['ttl']; |
115 } |
135 } |
116 return false; |
136 |
117 } |
137 return false; |
|
138 } |
|
139 |
118 /** |
140 /** |
119 * Return true if the log retention is enabled for the CDN |
141 * Return true if the log retention is enabled for the CDN |
120 * |
142 * |
121 * @return boolean |
143 * @return bool |
122 */ |
144 */ |
123 public function isCdnLogEnabled() |
145 public function isCdnLogEnabled() |
124 { |
146 { |
125 $data = $this->getCdnInfo(); |
147 $data = $this->getCdnInfo(); |
126 if (!isset($data['log_retention'])) { |
148 if (isset($data['log_retention'])) { |
127 return $data['log_retention']; |
149 return $data['log_retention']; |
128 } |
150 } |
129 return false; |
151 |
130 } |
152 return false; |
|
153 } |
|
154 |
131 /** |
155 /** |
132 * Get the CDN URI |
156 * Get the CDN URI |
133 * |
157 * |
134 * @return string|boolean |
158 * @return string|bool |
135 */ |
159 */ |
136 public function getCdnUri() |
160 public function getCdnUri() |
137 { |
161 { |
138 $data = $this->getCdnInfo(); |
162 $data = $this->getCdnInfo(); |
139 if (!isset($data['cdn_uri'])) { |
163 if (isset($data['cdn_uri'])) { |
140 return $data['cdn_uri']; |
164 return $data['cdn_uri']; |
141 } |
165 } |
142 return false; |
166 |
143 } |
167 return false; |
|
168 } |
|
169 |
144 /** |
170 /** |
145 * Get the CDN URI SSL |
171 * Get the CDN URI SSL |
146 * |
172 * |
147 * @return string|boolean |
173 * @return string|bool |
148 */ |
174 */ |
149 public function getCdnUriSsl() |
175 public function getCdnUriSsl() |
150 { |
176 { |
151 $data = $this->getCdnInfo(); |
177 $data = $this->getCdnInfo(); |
152 if (!isset($data['cdn_uri_ssl'])) { |
178 if (isset($data['cdn_uri_ssl'])) { |
153 return $data['cdn_uri_ssl']; |
179 return $data['cdn_uri_ssl']; |
154 } |
180 } |
155 return false; |
181 |
156 } |
182 return false; |
|
183 } |
|
184 |
157 /** |
185 /** |
158 * Get the metadata of the container |
186 * Get the metadata of the container |
159 * |
187 * |
160 * If $key is empty return the array of metadata |
188 * If $key is empty return the array of metadata |
161 * |
189 * |
162 * @param string $key |
190 * @param string $key |
163 * @return array|string|boolean |
191 * |
164 */ |
192 * @return array|string|bool |
165 public function getMetadata($key=null) |
193 */ |
|
194 public function getMetadata($key = null) |
166 { |
195 { |
167 $result = $this->service->getMetadataContainer($this->getName()); |
196 $result = $this->service->getMetadataContainer($this->getName()); |
168 if (!empty($result) && is_array($result)) { |
197 if (!empty($result) && is_array($result)) { |
169 if (empty($key)) { |
198 if (empty($key)) { |
170 return $result['metadata']; |
199 return $result['metadata']; |
171 } else { |
200 } else { |
172 if (isset ($result['metadata'][$key])) { |
201 if (isset ($result['metadata'][$key])) { |
173 return $result['metadata'][$key]; |
202 return $result['metadata'][$key]; |
174 } |
203 } |
175 } |
204 } |
176 } |
205 } |
177 return false; |
206 |
178 } |
207 return false; |
|
208 } |
|
209 |
179 /** |
210 /** |
180 * Get the information of the container (total of objects, total size) |
211 * Get the information of the container (total of objects, total size) |
181 * |
212 * |
182 * @return array|boolean |
213 * @return array|bool |
183 */ |
214 */ |
184 public function getInfo() |
215 public function getInfo() |
185 { |
216 { |
186 $result = $this->service->getMetadataContainer($this->getName()); |
217 $result = $this->service->getMetadataContainer($this->getName()); |
187 if (!empty($result) && is_array($result)) { |
218 if (!empty($result) && is_array($result)) { |
188 return $result; |
219 return $result; |
189 } |
220 } |
190 return false; |
221 |
191 } |
222 return false; |
|
223 } |
|
224 |
192 /** |
225 /** |
193 * Get all the object of the container |
226 * Get all the object of the container |
194 * |
227 * |
195 * @return Zend_Service_Rackspace_Files_ObjectList |
228 * @return Zend_Service_Rackspace_Files_ObjectList |
196 */ |
229 */ |
197 public function getObjects() |
230 public function getObjects() |
198 { |
231 { |
199 return $this->service->getObjects($this->getName()); |
232 return $this->service->getObjects($this->getName()); |
200 } |
233 } |
|
234 |
201 /** |
235 /** |
202 * Get an object of the container |
236 * Get an object of the container |
203 * |
237 * |
204 * @param string $name |
238 * @param string $name |
205 * @param array $headers |
239 * @param array $headers |
206 * @return Zend_Service_Rackspace_Files_Object|boolean |
240 * |
207 */ |
241 * @return Zend_Service_Rackspace_Files_Object|bool |
208 public function getObject($name, $headers=array()) |
242 */ |
|
243 public function getObject($name, $headers = array()) |
209 { |
244 { |
210 return $this->service->getObject($this->getName(), $name, $headers); |
245 return $this->service->getObject($this->getName(), $name, $headers); |
211 } |
246 } |
|
247 |
212 /** |
248 /** |
213 * Add an object in the container |
249 * Add an object in the container |
214 * |
250 * |
215 * @param string $name |
251 * @param string $name |
216 * @param string $file the content of the object |
252 * @param string $file the content of the object |
217 * @param array $metadata |
253 * @param array $metadata |
218 * @return boolen |
254 * |
219 */ |
255 * @return bool |
220 public function addObject($name, $file, $metadata=array()) |
256 */ |
221 { |
257 public function addObject($name, $file, $metadata = array()) |
222 return $this->service->storeObject($this->getName(), $name, $file, $metadata); |
258 { |
223 } |
259 return $this->service->storeObject( |
|
260 $this->getName(), $name, $file, $metadata |
|
261 ); |
|
262 } |
|
263 |
224 /** |
264 /** |
225 * Delete an object in the container |
265 * Delete an object in the container |
226 * |
266 * |
227 * @param string $obj |
267 * @param string $obj |
228 * @return boolean |
268 * |
|
269 * @return bool |
229 */ |
270 */ |
230 public function deleteObject($obj) |
271 public function deleteObject($obj) |
231 { |
272 { |
232 return $this->service->deleteObject($this->getName(), $obj); |
273 return $this->service->deleteObject($this->getName(), $obj); |
233 } |
274 } |
|
275 |
234 /** |
276 /** |
235 * Copy an object to another container |
277 * Copy an object to another container |
236 * |
278 * |
237 * @param string $obj_source |
279 * @param string $obj_source |
238 * @param string $container_dest |
280 * @param string $container_dest |
239 * @param string $obj_dest |
281 * @param string $obj_dest |
240 * @param array $metadata |
282 * @param array $metadata |
241 * @param string $content_type |
283 * @param string $content_type |
242 * @return boolean |
284 * |
243 */ |
285 * @return bool |
244 public function copyObject($obj_source, $container_dest, $obj_dest, $metadata=array(), $content_type=null) |
286 */ |
245 { |
287 public function copyObject( |
246 return $this->service->copyObject($this->getName(), $obj_source, $container_dest, $obj_dest, $metadata, $content_type); |
288 $obj_source, $container_dest, $obj_dest, $metadata = array(), |
247 } |
289 $content_type = null |
|
290 ) |
|
291 { |
|
292 return $this->service->copyObject( |
|
293 $this->getName(), |
|
294 $obj_source, |
|
295 $container_dest, |
|
296 $obj_dest, |
|
297 $metadata, |
|
298 $content_type |
|
299 ); |
|
300 } |
|
301 |
248 /** |
302 /** |
249 * Get the metadata of an object in the container |
303 * Get the metadata of an object in the container |
250 * |
304 * |
251 * @param string $object |
305 * @param string $object |
|
306 * |
252 * @return array |
307 * @return array |
253 */ |
308 */ |
254 public function getMetadataObject($object) |
309 public function getMetadataObject($object) |
255 { |
310 { |
256 return $this->service->getMetadataObject($this->getName(),$object); |
311 return $this->service->getMetadataObject($this->getName(), $object); |
257 } |
312 } |
|
313 |
258 /** |
314 /** |
259 * Set the metadata of an object in the container |
315 * Set the metadata of an object in the container |
260 * |
316 * |
261 * @param string $object |
317 * @param string $object |
262 * @param array $metadata |
318 * @param array $metadata |
263 * @return boolean |
319 * |
264 */ |
320 * @return bool |
265 public function setMetadataObject($object,$metadata=array()) |
321 */ |
266 { |
322 public function setMetadataObject($object, $metadata = array()) |
267 return $this->service->setMetadataObject($this->getName(),$object,$metadata); |
323 { |
268 } |
324 return $this->service->setMetadataObject( |
|
325 $this->getName(), $object, $metadata |
|
326 ); |
|
327 } |
|
328 |
269 /** |
329 /** |
270 * Enable the CDN for the container |
330 * Enable the CDN for the container |
271 * |
331 * |
272 * @param integer $ttl |
332 * @param integer $ttl |
273 * @return array|boolean |
333 * |
274 */ |
334 * @return array|bool |
275 public function enableCdn($ttl=Zend_Service_Rackspace_Files::CDN_TTL_MIN) |
335 */ |
276 { |
336 public function enableCdn($ttl = Zend_Service_Rackspace_Files::CDN_TTL_MIN) |
277 return $this->service->enableCdnContainer($this->getName(),$ttl); |
337 { |
278 } |
338 return $this->service->enableCdnContainer($this->getName(), $ttl); |
|
339 } |
|
340 |
279 /** |
341 /** |
280 * Disable the CDN for the container |
342 * Disable the CDN for the container |
281 * |
343 * |
282 * @return boolean |
344 * @return bool |
283 */ |
345 */ |
284 public function disableCdn() |
346 public function disableCdn() |
285 { |
347 { |
286 $result = $this->service->updateCdnContainer($this->getName(),null,false); |
348 $result = |
287 return ($result!==false); |
349 $this->service->updateCdnContainer($this->getName(), null, false); |
288 } |
350 |
|
351 return ($result !== false); |
|
352 } |
|
353 |
289 /** |
354 /** |
290 * Change the TTL for the CDN container |
355 * Change the TTL for the CDN container |
291 * |
356 * |
292 * @param integer $ttl |
357 * @param integer $ttl |
293 * @return boolean |
358 * |
294 */ |
359 * @return bool |
295 public function changeTtlCdn($ttl) |
360 */ |
296 { |
361 public function changeTtlCdn($ttl) |
297 $result = $this->service->updateCdnContainer($this->getName(),$ttl); |
362 { |
298 return ($result!==false); |
363 $result = $this->service->updateCdnContainer($this->getName(), $ttl); |
299 } |
364 |
|
365 return ($result !== false); |
|
366 } |
|
367 |
300 /** |
368 /** |
301 * Enable the log retention for the CDN |
369 * Enable the log retention for the CDN |
302 * |
370 * |
303 * @return boolean |
371 * @return bool |
304 */ |
372 */ |
305 public function enableLogCdn() |
373 public function enableLogCdn() |
306 { |
374 { |
307 $result = $this->service->updateCdnContainer($this->getName(),null,null,true); |
375 $result = $this->service->updateCdnContainer( |
308 return ($result!==false); |
376 $this->getName(), null, null, true |
309 } |
377 ); |
|
378 |
|
379 return ($result !== false); |
|
380 } |
|
381 |
310 /** |
382 /** |
311 * Disable the log retention for the CDN |
383 * Disable the log retention for the CDN |
312 * |
384 * |
313 * @return boolean |
385 * @return bool |
314 */ |
386 */ |
315 public function disableLogCdn() |
387 public function disableLogCdn() |
316 { |
388 { |
317 $result = $this->service->updateCdnContainer($this->getName(),null,null,false); |
389 $result = $this->service->updateCdnContainer( |
318 return ($result!==false); |
390 $this->getName(), null, null, false |
319 } |
391 ); |
|
392 |
|
393 return ($result !== false); |
|
394 } |
|
395 |
320 /** |
396 /** |
321 * Get the CDN information |
397 * Get the CDN information |
322 * |
398 * |
323 * @return array|boolean |
399 * @return array|bool |
324 */ |
400 */ |
325 public function getCdnInfo() |
401 public function getCdnInfo() |
326 { |
402 { |
327 return $this->service->getInfoCdnContainer($this->getName()); |
403 return $this->service->getInfoCdnContainer($this->getName()); |
328 } |
404 } |
329 } |
405 } |