-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFileInterface.php
317 lines (279 loc) · 6.67 KB
/
FileInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php declare(strict_types=1);
/**
* Copyright (c) Florian Krämer (https://florian-kraemer.net)
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
* @author Florian Krämer
* @link https://github.com/Phauthentic
* @license https://opensource.org/licenses/MIT MIT License
*/
namespace PhpCollective\Infrastructure\Storage;
use JsonSerializable;
use PhpCollective\Infrastructure\Storage\PathBuilder\PathBuilderInterface;
use PhpCollective\Infrastructure\Storage\UrlBuilder\UrlBuilderInterface;
/**
* File Interface
*/
interface FileInterface extends JsonSerializable
{
/**
* The uuid of the file
*
* @return string
*/
public function uuid(): string;
/**
* Filename
*
* @return string
*/
public function filename(): string;
/**
* Filesize
*
* @return int
*/
public function filesize(): int;
/**
* Mime Type
*
* @return string|null
*/
public function mimeType(): ?string;
/**
* Model name
*
* @return string|null
*/
public function model(): ?string;
/**
* Model ID
*
* @return string|null
*/
public function modelId(): ?string;
/**
* Gets the metadata array
*
* @return array<mixed, mixed>
*/
public function metadata(): array;
/**
* Resource to store
*
* @return resource|null
*/
public function resource();
/**
* Collection name
*
* @return string|null
*/
public function collection(): ?string;
/**
* Adds the file to a collection
*
* @param string $collection Collection
*
* @return $this
*/
public function addToCollection(string $collection);
/**
* Get a variant
*
* @param string $name
*
* @return array
*/
public function variant(string $name): array;
/**
* Array data structure of the variants
*
* @return array
*/
public function variants(): array;
/**
* Checks if the file has a specific variant
*
* @param string $name
*
* @return bool
*/
public function hasVariant(string $name): bool;
/**
* Checks if the file has any variants
*
* @return bool
*/
public function hasVariants(): bool;
/**
* @param string $name Name
* @param array $data Data
*
* @return self
*/
public function withVariant(string $name, array $data): self;
/**
* @param array $variants Variants
* @param bool $merge Merge variants, default is false
*
* @return self
*/
public function withVariants(array $variants, bool $merge = true): self;
/**
* Gets the paths for all variants
*
* @return array
*/
public function variantPaths(): array;
/**
* Returns an array of the file data
*
* @return array
*/
public function toArray(): array;
/**
* Adds (replaces) the existing metadata
*
* @param array<mixed, mixed> $metadata Metadata
* @param bool $overwrite
*
* @return self
*/
public function withMetadata(array $metadata, bool $overwrite = false): self;
/**
* Removes all metadata
*
* @return self
*/
public function withoutMetadata(): self;
/**
* Adds a single key and value to the metadata array
*
* @param string $key Key
* @param mixed $data
*
* @return self
*/
public function withMetadataByKey(string $key, $data): self;
/**
* Removes a key from the metadata array
*
* @param string $name Name
*
* @return self
*/
public function withoutMetadataByKey(string $name): self;
/**
* Stream resource of the file to be stored
*
* @param resource $resource
*
* @return self
*/
public function withResource($resource): self;
/**
* Same as withResource() but takes a file path
*
* @param string $file File
*
* @return self
*/
public function withFile(string $file): self;
/**
* Returns the path for the file in the storage system
*
* This is probably most of the time a *relative* and not an absolute path
* to some root or container depending on the storage backend.
*
* @return string
*/
public function path(): string;
/**
* Sets the path, immutable
*
* @param string $path Path to the file
*
* @return self
*/
public function withPath(string $path): self;
/**
* Builds the path for this file
*
* Keep in mind that the path will depend on the path builder configuration!
* The resulting path depends on the builder!
*
* @param \PhpCollective\Infrastructure\Storage\PathBuilder\PathBuilderInterface $pathBuilder Path Builder
*
* @return $this
*/
public function buildPath(PathBuilderInterface $pathBuilder): self;
/**
* Builds the URL for this file
*
* Keep in mind that the URL will depend on the URL builder configuration!
* The resulting URL depends on the builder!
*
* @param \PhpCollective\Infrastructure\Storage\UrlBuilder\UrlBuilderInterface $urlBuilder URL Builder
*
* @return $this
*/
public function buildUrl(UrlBuilderInterface $urlBuilder);
/**
* Gets the URL for the file
*
* @return string
*/
public function url(): string;
/**
* Sets a URL
*
* @param string $url URL
*
* @return self
*/
public function withUrl(string $url): self;
/**
* Storage name
*
* @return string
*/
public function storage(): string;
/**
* Returns the filenames extension
*
* @return string|null
*/
public function extension(): ?string;
/**
* UUID of the file
*
* @param string $uuid UUID string
*
* @return self
*/
public function withUuid(string $uuid): self;
/**
* Filename
*
* Be aware that the filename doesn't have to match the name of the actual
* file in the storage backend!
*
* @param string $filename Filename
*
* @return self
*/
public function withFilename(string $filename): self;
/**
* Assign a model and model id to a file
*
* @param string $model Model
* @param string|int $modelId Model ID, UUID string or integer
*
* @return $this
*/
public function belongsToModel(string $model, $modelId);
}