27 * The service that has created the object |
27 * The service that has created the object |
28 * |
28 * |
29 * @var Zend_Service_Rackspace_Files |
29 * @var Zend_Service_Rackspace_Files |
30 */ |
30 */ |
31 protected $service; |
31 protected $service; |
|
32 |
32 /** |
33 /** |
33 * Name of the object |
34 * Name of the object |
34 * |
35 * |
35 * @var string |
36 * @var string |
36 */ |
37 */ |
37 protected $name; |
38 protected $name; |
|
39 |
38 /** |
40 /** |
39 * MD5 value of the object's content |
41 * MD5 value of the object's content |
40 * |
42 * |
41 * @var string |
43 * @var string |
42 */ |
44 */ |
43 protected $hash; |
45 protected $hash; |
|
46 |
44 /** |
47 /** |
45 * Size in bytes of the object's content |
48 * Size in bytes of the object's content |
46 * |
49 * |
47 * @var integer |
50 * @var integer |
48 */ |
51 */ |
49 protected $size; |
52 protected $size; |
|
53 |
50 /** |
54 /** |
51 * Content type of the object's content |
55 * Content type of the object's content |
52 * |
56 * |
53 * @var string |
57 * @var string |
54 */ |
58 */ |
55 protected $contentType; |
59 protected $contentType; |
|
60 |
56 /** |
61 /** |
57 * Date of the last modified of the object |
62 * Date of the last modified of the object |
58 * |
63 * |
59 * @var string |
64 * @var string |
60 */ |
65 */ |
61 protected $lastModified; |
66 protected $lastModified; |
|
67 |
62 /** |
68 /** |
63 * Object content |
69 * Object content |
64 * |
70 * |
65 * @var string |
71 * @var string |
66 */ |
72 */ |
67 protected $content; |
73 protected $content; |
|
74 |
68 /** |
75 /** |
69 * Name of the container where the object is stored |
76 * Name of the container where the object is stored |
70 * |
77 * |
71 * @var string |
78 * @var string |
72 */ |
79 */ |
73 protected $container; |
80 protected $container; |
|
81 |
74 /** |
82 /** |
75 * Constructor |
83 * Constructor |
76 * |
84 * |
77 * You must pass the Zend_Service_Rackspace_Files object of the caller and an associative |
85 * 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", |
86 * array with the keys "name", "container", "hash", "bytes", "content_type", |
79 * "last_modified", "file" where: |
87 * "last_modified", "file" where: |
80 * name= name of the object |
88 * name= name of the object |
81 * container= name of the container where the object is stored |
89 * container= name of the container where the object is stored |
82 * hash= the MD5 of the object's content |
90 * hash= the MD5 of the object's content |
83 * bytes= size in bytes of the object's content |
91 * bytes= size in bytes of the object's content |
84 * content_type= content type of the object's content |
92 * content_type= content type of the object's content |
85 * last_modified= date of the last modified of the object |
93 * last_modified= date of the last modified of the object |
86 * content= content of the object |
94 * content= content of the object |
87 * |
95 * |
88 * @param Zend_Service_Rackspace_Files $service |
96 * @param Zend_Service_Rackspace_Files $service |
89 * @param array $data |
97 * @param array $data |
90 */ |
98 * @throws Zend_Service_Rackspace_Files_Exception |
91 public function __construct($service,$data) |
99 */ |
|
100 public function __construct($service, $data) |
92 { |
101 { |
93 if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) { |
102 if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) { |
94 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
103 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
95 throw new Zend_Service_Rackspace_Files_Exception("You must pass a RackspaceFiles and an array"); |
104 throw new Zend_Service_Rackspace_Files_Exception( |
96 } |
105 'You must pass a RackspaceFiles and an array' |
97 if (!array_key_exists('name', $data)) { |
106 ); |
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 } |
107 } |
101 if (!array_key_exists('container', $data)) { |
108 if (!array_key_exists('container', $data)) { |
102 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
109 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)"); |
110 throw new Zend_Service_Rackspace_Files_Exception( |
104 } |
111 'You must pass the container of the object in the array (container)' |
105 if (!array_key_exists('hash', $data)) { |
112 ); |
|
113 } |
|
114 if (array_key_exists('name', $data)) { |
|
115 if (!array_key_exists('hash', $data)) { |
|
116 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
117 throw new Zend_Service_Rackspace_Files_Exception( |
|
118 'You must pass the hash of the object in the array (hash)' |
|
119 ); |
|
120 } |
|
121 if (!array_key_exists('bytes', $data)) { |
|
122 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
123 throw new Zend_Service_Rackspace_Files_Exception( |
|
124 'You must pass the byte size of the object in the array (bytes)' |
|
125 ); |
|
126 } |
|
127 if (!array_key_exists('content_type', $data)) { |
|
128 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
129 throw new Zend_Service_Rackspace_Files_Exception( |
|
130 'You must pass the content type of the object in the array (content_type)' |
|
131 ); |
|
132 } |
|
133 if (!array_key_exists('last_modified', $data)) { |
|
134 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
|
135 throw new Zend_Service_Rackspace_Files_Exception( |
|
136 'You must pass the last modified data of the object in the array (last_modified)' |
|
137 ); |
|
138 } |
|
139 |
|
140 $this->name = $data['name']; |
|
141 $this->hash = $data['hash']; |
|
142 $this->size = $data['bytes']; |
|
143 $this->contentType = $data['content_type']; |
|
144 $this->lastModified = $data['last_modified']; |
|
145 |
|
146 if (!empty($data['content'])) { |
|
147 $this->content = $data['content']; |
|
148 } |
|
149 } elseif (array_key_exists('subdir', $data)) { |
|
150 $this->name = $data['subdir']; |
|
151 } else { |
106 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
152 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)"); |
153 throw new Zend_Service_Rackspace_Files_Exception( |
108 } |
154 'You must pass the name of the object in the array (name)' |
109 if (!array_key_exists('bytes', $data)) { |
155 ); |
110 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
156 } |
111 throw new Zend_Service_Rackspace_Files_Exception("You must pass the byte size of the object in the array (bytes)"); |
157 |
112 } |
158 $this->container = $data['container']; |
113 if (!array_key_exists('content_type', $data)) { |
159 $this->service = $service; |
114 require_once 'Zend/Service/Rackspace/Files/Exception.php'; |
160 } |
115 throw new Zend_Service_Rackspace_Files_Exception("You must pass the content type of the object in the array (content_type)"); |
161 |
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 /** |
162 /** |
133 * Get name |
163 * Get name |
134 * |
164 * |
135 * @return string |
165 * @return string |
136 */ |
166 */ |
137 public function getName() |
167 public function getName() |
138 { |
168 { |
139 return $this->name; |
169 return $this->name; |
140 } |
170 } |
|
171 |
141 /** |
172 /** |
142 * Get the name of the container |
173 * Get the name of the container |
143 * |
174 * |
144 * @return string |
175 * @return string |
145 */ |
176 */ |
146 public function getContainer() |
177 public function getContainer() |
147 { |
178 { |
148 return $this->container; |
179 return $this->container; |
149 } |
180 } |
|
181 |
150 /** |
182 /** |
151 * Get the MD5 of the object's content |
183 * Get the MD5 of the object's content |
152 * |
184 * |
153 * @return string|boolean |
185 * @return string|boolean |
154 */ |
186 */ |
155 public function getHash() |
187 public function getHash() |
156 { |
188 { |
157 return $this->hash; |
189 return $this->hash; |
158 } |
190 } |
|
191 |
159 /** |
192 /** |
160 * Get the size (in bytes) of the object's content |
193 * Get the size (in bytes) of the object's content |
161 * |
194 * |
162 * @return integer|boolean |
195 * @return integer|boolean |
163 */ |
196 */ |
164 public function getSize() |
197 public function getSize() |
165 { |
198 { |
166 return $this->size; |
199 return $this->size; |
167 } |
200 } |
|
201 |
168 /** |
202 /** |
169 * Get the content type of the object's content |
203 * Get the content type of the object's content |
170 * |
204 * |
171 * @return string |
205 * @return string |
172 */ |
206 */ |
173 public function getContentType() |
207 public function getContentType() |
174 { |
208 { |
175 return $this->contentType; |
209 return $this->contentType; |
176 } |
210 } |
|
211 |
177 /** |
212 /** |
178 * Get the data of the last modified of the object |
213 * Get the data of the last modified of the object |
179 * |
214 * |
180 * @return string |
215 * @return string |
181 */ |
216 */ |
182 public function getLastModified() |
217 public function getLastModified() |
183 { |
218 { |
184 return $this->lastModified; |
219 return $this->lastModified; |
185 } |
220 } |
|
221 |
186 /** |
222 /** |
187 * Get the content of the object |
223 * Get the content of the object |
188 * |
224 * |
189 * @return string |
225 * @return string |
190 */ |
226 */ |
191 public function getContent() |
227 public function getContent() |
192 { |
228 { |
193 return $this->content; |
229 return $this->content; |
194 } |
230 } |
|
231 |
195 /** |
232 /** |
196 * Get the metadata of the object |
233 * Get the metadata of the object |
197 * If you don't pass the $key it returns the entire array of metadata value |
234 * If you don't pass the $key it returns the entire array of metadata value |
198 * |
235 * |
199 * @param string $key |
236 * @param string $key |