|
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 Files |
|
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 */ |
|
21 |
|
22 require_once 'Zend/Service/Rackspace/Files.php'; |
|
23 |
|
24 class Zend_Service_Rackspace_Files_Object |
|
25 { |
|
26 /** |
|
27 * The service that has created the object |
|
28 * |
|
29 * @var Zend_Service_Rackspace_Files |
|
30 */ |
|
31 protected $service; |
|
32 /** |
|
33 * Name of the object |
|
34 * |
|
35 * @var string |
|
36 */ |
|
37 protected $name; |
|
38 /** |
|
39 * MD5 value of the object's content |
|
40 * |
|
41 * @var string |
|
42 */ |
|
43 protected $hash; |
|
44 /** |
|
45 * Size in bytes of the object's content |
|
46 * |
|
47 * @var integer |
|
48 */ |
|
49 protected $size; |
|
50 /** |
|
51 * Content type of the object's content |
|
52 * |
|
53 * @var string |
|
54 */ |
|
55 protected $contentType; |
|
56 /** |
|
57 * Date of the last modified of the object |
|
58 * |
|
59 * @var string |
|
60 */ |
|
61 protected $lastModified; |
|
62 /** |
|
63 * Object content |
|
64 * |
|
65 * @var string |
|
66 */ |
|
67 protected $content; |
|
68 /** |
|
69 * Name of the container where the object is stored |
|
70 * |
|
71 * @var string |
|
72 */ |
|
73 protected $container; |
|
74 /** |
|
75 * Constructor |
|
76 * |
|
77 * You must pass the Zend_Service_Rackspace_Files object of the caller and an associative |
|
78 * array with the keys "name", "container", "hash", "bytes", "content_type", |
|
79 * "last_modified", "file" where: |
|
80 * name= name of the object |
|
81 * container= name of the container where the object is stored |
|
82 * hash= the MD5 of the object's content |
|
83 * bytes= size in bytes of the object's content |
|
84 * content_type= content type of the object's content |
|
85 * last_modified= date of the last modified of the object |
|
86 * content= content of the object |
|
87 * |
|
88 * @param Zend_Service_Rackspace_Files $service |
|
89 * @param array $data |
|
90 */ |
|
91 public function __construct($service,$data) |
|
92 { |
|
93 if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) { |
|
94 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
95 throw new Zend_Service_Rackspace_Files_Exception("You must pass a RackspaceFiles and an array"); |
|
96 } |
|
97 if (!array_key_exists('name', $data)) { |
|
98 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
99 throw new Zend_Service_Rackspace_Files_Exception("You must pass the name of the object in the array (name)"); |
|
100 } |
|
101 if (!array_key_exists('container', $data)) { |
|
102 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
103 throw new Zend_Service_Rackspace_Files_Exception("You must pass the container of the object in the array (container)"); |
|
104 } |
|
105 if (!array_key_exists('hash', $data)) { |
|
106 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
107 throw new Zend_Service_Rackspace_Files_Exception("You must pass the hash of the object in the array (hash)"); |
|
108 } |
|
109 if (!array_key_exists('bytes', $data)) { |
|
110 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
111 throw new Zend_Service_Rackspace_Files_Exception("You must pass the byte size of the object in the array (bytes)"); |
|
112 } |
|
113 if (!array_key_exists('content_type', $data)) { |
|
114 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
115 throw new Zend_Service_Rackspace_Files_Exception("You must pass the content type of the object in the array (content_type)"); |
|
116 } |
|
117 if (!array_key_exists('last_modified', $data)) { |
|
118 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
119 throw new Zend_Service_Rackspace_Files_Exception("You must pass the last modified data of the object in the array (last_modified)"); |
|
120 } |
|
121 $this->name= $data['name']; |
|
122 $this->container= $data['container']; |
|
123 $this->hash= $data['hash']; |
|
124 $this->size= $data['bytes']; |
|
125 $this->contentType= $data['content_type']; |
|
126 $this->lastModified= $data['last_modified']; |
|
127 if (!empty($data['content'])) { |
|
128 $this->content= $data['content']; |
|
129 } |
|
130 $this->service= $service; |
|
131 } |
|
132 /** |
|
133 * Get name |
|
134 * |
|
135 * @return string |
|
136 */ |
|
137 public function getName() |
|
138 { |
|
139 return $this->name; |
|
140 } |
|
141 /** |
|
142 * Get the name of the container |
|
143 * |
|
144 * @return string |
|
145 */ |
|
146 public function getContainer() |
|
147 { |
|
148 return $this->container; |
|
149 } |
|
150 /** |
|
151 * Get the MD5 of the object's content |
|
152 * |
|
153 * @return string|boolean |
|
154 */ |
|
155 public function getHash() |
|
156 { |
|
157 return $this->hash; |
|
158 } |
|
159 /** |
|
160 * Get the size (in bytes) of the object's content |
|
161 * |
|
162 * @return integer|boolean |
|
163 */ |
|
164 public function getSize() |
|
165 { |
|
166 return $this->size; |
|
167 } |
|
168 /** |
|
169 * Get the content type of the object's content |
|
170 * |
|
171 * @return string |
|
172 */ |
|
173 public function getContentType() |
|
174 { |
|
175 return $this->contentType; |
|
176 } |
|
177 /** |
|
178 * Get the data of the last modified of the object |
|
179 * |
|
180 * @return string |
|
181 */ |
|
182 public function getLastModified() |
|
183 { |
|
184 return $this->lastModified; |
|
185 } |
|
186 /** |
|
187 * Get the content of the object |
|
188 * |
|
189 * @return string |
|
190 */ |
|
191 public function getContent() |
|
192 { |
|
193 return $this->content; |
|
194 } |
|
195 /** |
|
196 * Get the metadata of the object |
|
197 * If you don't pass the $key it returns the entire array of metadata value |
|
198 * |
|
199 * @param string $key |
|
200 * @return string|array|boolean |
|
201 */ |
|
202 public function getMetadata($key=null) |
|
203 { |
|
204 $result= $this->service->getMetadataObject($this->container,$this->name); |
|
205 if (!empty($result)) { |
|
206 if (empty($key)) { |
|
207 return $result['metadata']; |
|
208 } |
|
209 if (isset($result['metadata'][$key])) { |
|
210 return $result['metadata'][$key]; |
|
211 } |
|
212 } |
|
213 return false; |
|
214 } |
|
215 /** |
|
216 * Set the metadata value |
|
217 * The old metadata values are replaced with the new one |
|
218 * |
|
219 * @param array $metadata |
|
220 * @return boolean |
|
221 */ |
|
222 public function setMetadata($metadata) |
|
223 { |
|
224 return $this->service->setMetadataObject($this->container,$this->name,$metadata); |
|
225 } |
|
226 /** |
|
227 * Copy the object to another container |
|
228 * You can add metadata information to the destination object, change the |
|
229 * content_type and the name of the object |
|
230 * |
|
231 * @param string $container_dest |
|
232 * @param string $name_dest |
|
233 * @param array $metadata |
|
234 * @param string $content_type |
|
235 * @return boolean |
|
236 */ |
|
237 public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) |
|
238 { |
|
239 return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type); |
|
240 } |
|
241 /** |
|
242 * Get the CDN URL of the object |
|
243 * |
|
244 * @return string |
|
245 */ |
|
246 public function getCdnUrl() |
|
247 { |
|
248 $result= $this->service->getInfoCdnContainer($this->container); |
|
249 if ($result!==false) { |
|
250 if ($result['cdn_enabled']) { |
|
251 return $result['cdn_uri'].'/'.$this->name; |
|
252 } |
|
253 } |
|
254 return false; |
|
255 } |
|
256 /** |
|
257 * Get the CDN SSL URL of the object |
|
258 * |
|
259 * @return string |
|
260 */ |
|
261 public function getCdnUrlSsl() |
|
262 { |
|
263 $result= $this->service->getInfoCdnContainer($this->container); |
|
264 if ($result!==false) { |
|
265 if ($result['cdn_enabled']) { |
|
266 return $result['cdn_uri_ssl'].'/'.$this->name; |
|
267 } |
|
268 } |
|
269 return false; |
|
270 } |
|
271 } |