1 | <?php |
||
13 | class File implements FileContract, JsonSerializable |
||
14 | { |
||
15 | /** |
||
16 | * @var \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract |
||
17 | */ |
||
18 | protected $api; |
||
19 | |||
20 | /** |
||
21 | * Container name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $container; |
||
26 | |||
27 | /** |
||
28 | * File info. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $data; |
||
33 | |||
34 | /** |
||
35 | * Determines if current file was recently deleted. |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $deleted = false; |
||
40 | |||
41 | /** |
||
42 | * @param \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract $api |
||
43 | * @param string $container |
||
44 | * @param array $data |
||
45 | */ |
||
46 | public function __construct(ApiClientContract $api, $container, array $data) |
||
52 | |||
53 | /** |
||
54 | * Returns specific file data. |
||
55 | * |
||
56 | * @param string $key |
||
57 | * @param mixed $default = null |
||
58 | * |
||
59 | * @throws \LogicException |
||
60 | * |
||
61 | * @return mixed|null |
||
62 | */ |
||
63 | protected function fileData($key, $default = null) |
||
69 | |||
70 | /** |
||
71 | * Absolute path to file from storage root. |
||
72 | * |
||
73 | * @param string $path = '' Relative file path. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | protected function absolutePath($path = '') |
||
85 | |||
86 | /** |
||
87 | * Container name. |
||
88 | * |
||
89 | * @throws \LogicException |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function container() |
||
97 | |||
98 | /** |
||
99 | * Full path to file. |
||
100 | * |
||
101 | * @throws \LogicException |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function path() |
||
109 | |||
110 | /** |
||
111 | * File directory. |
||
112 | * |
||
113 | * @throws \LogicException |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | public function directory() |
||
125 | |||
126 | /** |
||
127 | * File name. |
||
128 | * |
||
129 | * @throws \LogicException |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function name() |
||
139 | |||
140 | /** |
||
141 | * File size in bytes. |
||
142 | * |
||
143 | * @throws \LogicException |
||
144 | * |
||
145 | * @return int |
||
146 | */ |
||
147 | public function size() |
||
151 | |||
152 | /** |
||
153 | * File content type. |
||
154 | * |
||
155 | * @throws \LogicException |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function contentType() |
||
163 | |||
164 | /** |
||
165 | * Date of last modification. |
||
166 | * |
||
167 | * @throws \LogicException |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function lastModifiedAt() |
||
175 | |||
176 | /** |
||
177 | * File ETag. |
||
178 | * |
||
179 | * @throws \LogicException |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function etag() |
||
187 | |||
188 | /** |
||
189 | * Determines if current file was recently deleted. |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function isDeleted() |
||
197 | |||
198 | /** |
||
199 | * Reads file contents. |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | public function read() |
||
209 | |||
210 | /** |
||
211 | * Reads file contents as stream. |
||
212 | * |
||
213 | * @param bool $psr7Stream = false |
||
214 | * |
||
215 | * @return resource|\Psr\Http\Message\StreamInterface |
||
216 | */ |
||
217 | public function readStream($psr7Stream = false) |
||
227 | |||
228 | /** |
||
229 | * Rename file. New file name must be provided without path. |
||
230 | * |
||
231 | * @param string $name |
||
232 | * |
||
233 | * @throws \LogicException |
||
234 | * @throws \InvalidArgumentException |
||
235 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | public function rename($name) |
||
276 | |||
277 | /** |
||
278 | * Copy file to given destination. |
||
279 | * |
||
280 | * @param string $destination |
||
281 | * @param string $destinationContainer = null |
||
282 | * |
||
283 | * @throws \LogicException |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | public function copy($destination, $destinationContainer = null) |
||
312 | |||
313 | /** |
||
314 | * Deletes file. |
||
315 | * |
||
316 | * @throws \LogicException |
||
317 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
318 | */ |
||
319 | public function delete() |
||
336 | |||
337 | /** |
||
338 | * JSON representation of file. |
||
339 | * |
||
340 | * @return array |
||
341 | */ |
||
342 | public function jsonSerialize() |
||
355 | |||
356 | /** |
||
357 | * Protects FileAPI from unwanted requests. |
||
358 | * |
||
359 | * @throws \LogicException |
||
360 | */ |
||
361 | protected function guardDeletedFile() |
||
367 | } |
||
368 |