1 | <?php |
||
15 | class Container implements ContainerContract, Countable, JsonSerializable |
||
16 | { |
||
17 | /** |
||
18 | * @var \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract $api |
||
19 | */ |
||
20 | protected $api; |
||
21 | |||
22 | /** |
||
23 | * Container name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name; |
||
28 | |||
29 | /** |
||
30 | * Container data. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $data = []; |
||
35 | |||
36 | /** |
||
37 | * Determines if container data was already loaded. |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $dataLoaded = false; |
||
42 | |||
43 | /** |
||
44 | * @param \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract $api |
||
45 | * @param string $name |
||
46 | * @param array $data |
||
47 | */ |
||
48 | public function __construct(ApiClientContract $api, $name, array $data = []) |
||
55 | |||
56 | /** |
||
57 | * Returns specific container data. |
||
58 | * |
||
59 | * @param string $key |
||
60 | * @param mixed $default = null |
||
61 | * |
||
62 | * @return mixed |
||
63 | */ |
||
64 | protected function containerData($key, $default = null) |
||
72 | |||
73 | /** |
||
74 | * Lazy loading for container data. |
||
75 | * |
||
76 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
77 | */ |
||
78 | protected function loadContainerData() |
||
102 | |||
103 | /** |
||
104 | * Container name. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function name() |
||
112 | |||
113 | /** |
||
114 | * Container visibility type. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function type() |
||
122 | |||
123 | /** |
||
124 | * Container files count. |
||
125 | * |
||
126 | * @return int |
||
127 | */ |
||
128 | public function filesCount() |
||
132 | |||
133 | /** |
||
134 | * Container files count. |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | public function count() |
||
142 | |||
143 | /** |
||
144 | * Container size in bytes. |
||
145 | * |
||
146 | * @return int |
||
147 | */ |
||
148 | public function size() |
||
152 | |||
153 | /** |
||
154 | * Total uploaded (received) bytes. |
||
155 | * |
||
156 | * @return int |
||
157 | */ |
||
158 | public function uploadedBytes() |
||
162 | |||
163 | /** |
||
164 | * Total downloaded (transmitted) bytes. |
||
165 | * |
||
166 | * @return int |
||
167 | */ |
||
168 | public function downloadedBytes() |
||
172 | |||
173 | /** |
||
174 | * Returns JSON representation of container. |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | public function jsonSerialize() |
||
189 | |||
190 | /** |
||
191 | * Determines if container is public. |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function isPublic() |
||
199 | |||
200 | /** |
||
201 | * Determines if container is private. |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function isPrivate() |
||
209 | |||
210 | /** |
||
211 | * Retrieves files from current container. |
||
212 | * |
||
213 | * @param string $directory = null |
||
214 | * @param string $prefixOrFullPath = null |
||
215 | * @param string $delimiter = null |
||
216 | * @param int $limit = 10000 |
||
217 | * @param string $marker = '' |
||
218 | * |
||
219 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\Collections\CollectionContract |
||
220 | */ |
||
221 | public function files($directory = null, $prefixOrFullPath = null, $delimiter = null, $limit = 10000, $marker = '') |
||
239 | |||
240 | /** |
||
241 | * Retrieves file object container. This method does not actually download file, see File::download. |
||
242 | * |
||
243 | * @param string $path |
||
244 | * |
||
245 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\FileNotFoundException |
||
246 | * @throws \LogicException |
||
247 | * |
||
248 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FileContract |
||
249 | */ |
||
250 | public function getFile($path) |
||
264 | |||
265 | /** |
||
266 | * Uploads file contents from string. Returns ETag header value if upload was successful. |
||
267 | * |
||
268 | * @param string $path Remote path. |
||
269 | * @param string $contents File contents. |
||
270 | * @param array $params = [] Upload params. |
||
271 | * @param bool $verifyChecksum = true |
||
272 | * |
||
273 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\UploadFailedException |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public function uploadFromString($path, $contents, array $params = [], $verifyChecksum = true) |
||
281 | |||
282 | /** |
||
283 | * Uploads file from stream. Returns ETag header value if upload was successful. |
||
284 | * |
||
285 | * @param string $path Remote path. |
||
286 | * @param resource $resource Stream resource. |
||
287 | * @param array $params = [] Upload params. |
||
288 | * |
||
289 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\UploadFailedException |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function uploadFromStream($path, $resource, array $params = []) |
||
297 | |||
298 | /** |
||
299 | * Upload file from string or stream resource. |
||
300 | * |
||
301 | * @param string $path Remote path. |
||
302 | * @param string | resource $contents File contents. |
||
303 | * @param array $params = [] Upload params. |
||
304 | * @param bool $verifyChecksum = true |
||
305 | * |
||
306 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\UploadFailedException |
||
307 | * |
||
308 | * @return string |
||
309 | */ |
||
310 | protected function uploadFrom($path, $contents, array $params = [], $verifyChecksum = true) |
||
326 | |||
327 | /** |
||
328 | * Parses upload parameters and assigns them to appropriate HTTP headers. |
||
329 | * |
||
330 | * @param string $contents = null |
||
331 | * @param array $params = [] |
||
332 | * @param bool $verifyChecksum = true |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | protected function convertUploadParamsToHeaders($contents = null, array $params = [], $verifyChecksum = true) |
||
359 | |||
360 | /** |
||
361 | * Normalizes upload path. |
||
362 | * |
||
363 | * @param string $path Remote path (without container name). |
||
364 | * |
||
365 | * @return string |
||
366 | */ |
||
367 | protected function normalizeUploadPath($path) |
||
371 | |||
372 | /** |
||
373 | * Deletes container. Container must be empty in order to perform this operation. |
||
374 | * |
||
375 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
376 | */ |
||
377 | public function delete() |
||
391 | } |
||
392 |