1 | <?php |
||
13 | class FluentFilesLoader implements FluentFilesLoaderContract, FilesTransformerContract |
||
14 | { |
||
15 | use FilesTransformer; |
||
16 | |||
17 | /** |
||
18 | * API Client. |
||
19 | * |
||
20 | * @var \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract |
||
21 | */ |
||
22 | protected $api; |
||
23 | |||
24 | /** |
||
25 | * Container name. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $containerName = ''; |
||
30 | |||
31 | /** |
||
32 | * Container URL. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $containerUrl = ''; |
||
37 | |||
38 | /** |
||
39 | * Default parameters. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $params = [ |
||
44 | 'limit' => 10000, |
||
45 | 'marker' => '', |
||
46 | 'path' => '', |
||
47 | 'prefix' => '', |
||
48 | 'delimiter' => '', |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * Determines if resulting Collection should container File objects |
||
53 | * instead of file arrays. |
||
54 | * |
||
55 | * @var bool |
||
56 | */ |
||
57 | protected $asFileObjects = false; |
||
58 | |||
59 | /** |
||
60 | * @param \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract $api |
||
61 | * @param string $container |
||
62 | * @param string $containerUrl |
||
63 | */ |
||
64 | public function __construct(ApiClientContract $api, $container, $containerUrl) |
||
70 | |||
71 | /** |
||
72 | * Sets loader parameter. |
||
73 | * |
||
74 | * @param string $key |
||
75 | * @param string|int $value |
||
76 | * @param bool $trimLeadingSlashes = true |
||
77 | * |
||
78 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
79 | */ |
||
80 | protected function setParam($key, $value, $trimLeadingSlashes = true) |
||
86 | |||
87 | /** |
||
88 | * API Client. |
||
89 | * |
||
90 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract |
||
91 | */ |
||
92 | public function apiClient() |
||
96 | |||
97 | /** |
||
98 | * Container name. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function containerName() |
||
106 | |||
107 | /** |
||
108 | * Sets directory from where load files. This value may be overwritten |
||
109 | * to empty string if you're loading prefixed files from directory. |
||
110 | * |
||
111 | * @param string $directory |
||
112 | * |
||
113 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
114 | */ |
||
115 | public function fromDirectory($directory) |
||
119 | |||
120 | /** |
||
121 | * Sets files prefix. If you're planning to find prefixed files from a directory |
||
122 | * (using along with fromDirectory method), do not provide path to a directory |
||
123 | * here, since it will be appended to final prefix (before sending request). |
||
124 | * |
||
125 | * @param string $prefix |
||
126 | * |
||
127 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
128 | */ |
||
129 | public function withPrefix($prefix) |
||
133 | |||
134 | /** |
||
135 | * Sets files delimiter. |
||
136 | * |
||
137 | * @param string $delimiter |
||
138 | * |
||
139 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
140 | */ |
||
141 | public function withDelimiter($delimiter) |
||
145 | |||
146 | /** |
||
147 | * Sets files limit. If you need to paginate through results, pass markerFile |
||
148 | * argument with latest filename from previous request as value. If you're |
||
149 | * working within a directory, its path will be appended to markerFile. |
||
150 | * |
||
151 | * @param int $limit |
||
152 | * @param string $markerFile = '' |
||
153 | * |
||
154 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
155 | */ |
||
156 | public function limit($limit, $markerFile = '') |
||
161 | |||
162 | /** |
||
163 | * Tells builder to return Collection of File objects instead of arrays. |
||
164 | * |
||
165 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
166 | */ |
||
167 | public function asFileObjects() |
||
173 | |||
174 | /** |
||
175 | * Loads all available files from container. |
||
176 | * |
||
177 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
178 | * |
||
179 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\Collections\CollectionContract |
||
180 | */ |
||
181 | public function all() |
||
189 | |||
190 | /** |
||
191 | * Determines whether file exists or not. |
||
192 | * |
||
193 | * @param string $path File path. |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function exists($path) |
||
201 | |||
202 | /** |
||
203 | * Finds single file at given path. |
||
204 | * |
||
205 | * @param string $path |
||
206 | * |
||
207 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\FileNotFoundException |
||
208 | * |
||
209 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FileContract |
||
210 | */ |
||
211 | public function find($path) |
||
221 | |||
222 | /** |
||
223 | * Loads file from path. |
||
224 | * |
||
225 | * @param string $path |
||
226 | * |
||
227 | * @return array|null |
||
228 | */ |
||
229 | protected function findFileAt($path) |
||
243 | |||
244 | /** |
||
245 | * Loads files. |
||
246 | * |
||
247 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\ApiRequestFailedException |
||
248 | * |
||
249 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\Collections\CollectionContract |
||
250 | */ |
||
251 | public function get() |
||
282 | |||
283 | /** |
||
284 | * Builds query parameters. |
||
285 | * |
||
286 | * @return array |
||
287 | */ |
||
288 | protected function buildParams() |
||
303 | |||
304 | /** |
||
305 | * @param string $key |
||
306 | * @param bool $dropPath = false |
||
307 | * |
||
308 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FluentFilesLoaderContract |
||
309 | */ |
||
310 | protected function appendPathToParam($key, $dropPath = false) |
||
324 | } |
||
325 |