1 | <?php |
||
18 | class FileAdder |
||
19 | { |
||
20 | /** |
||
21 | * @var \Illuminate\Database\Eloquent\Model subject |
||
22 | */ |
||
23 | protected $subject; |
||
24 | |||
25 | /** |
||
26 | * @var Filesystem |
||
27 | */ |
||
28 | protected $filesystem; |
||
29 | |||
30 | /** |
||
31 | * @var Repository |
||
32 | */ |
||
33 | protected $config; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | protected $preserveOriginal = false; |
||
39 | |||
40 | /** |
||
41 | * @var string|\Symfony\Component\HttpFoundation\File\UploadedFile |
||
42 | */ |
||
43 | protected $file; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $properties = []; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $customProperties = []; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $pathToFile; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $fileName; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $mediaName; |
||
69 | |||
70 | /** |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $diskName = ''; |
||
74 | |||
75 | /** |
||
76 | * @param Filesystem $fileSystem |
||
77 | * @param Repository $config |
||
78 | */ |
||
79 | public function __construct(Filesystem $fileSystem, Repository $config) |
||
84 | |||
85 | /** |
||
86 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
87 | * |
||
88 | * @return FileAdder |
||
89 | */ |
||
90 | public function setSubject(Model $subject) |
||
96 | |||
97 | /** |
||
98 | * Set the file that needs to be imported. |
||
99 | * |
||
100 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function setFile($file) |
||
134 | |||
135 | /** |
||
136 | * When adding the file to the media library, the original file |
||
137 | * will be preserved. |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function preservingOriginal() |
||
147 | |||
148 | /** |
||
149 | * Set the name of the media object. |
||
150 | * |
||
151 | * @param string $name |
||
152 | * |
||
153 | * @return $this |
||
154 | */ |
||
155 | public function usingName(string $name) |
||
159 | |||
160 | /** |
||
161 | * Set the name of the media object. |
||
162 | * |
||
163 | * @param string $name |
||
164 | * |
||
165 | * @return $this |
||
166 | */ |
||
167 | public function setName(string $name) |
||
173 | |||
174 | /** |
||
175 | * Set the name of the file that is stored on disk. |
||
176 | * |
||
177 | * @param string $fileName |
||
178 | * |
||
179 | * @return $this |
||
180 | */ |
||
181 | public function usingFileName(string $fileName) |
||
185 | |||
186 | /** |
||
187 | * Set the name of the file that is stored on disk. |
||
188 | * |
||
189 | * @param string $fileName |
||
190 | * |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function setFileName(string $fileName) |
||
199 | |||
200 | /** |
||
201 | * Set the metadata. |
||
202 | * |
||
203 | * @param array $customProperties |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function withCustomProperties(array $customProperties) |
||
213 | |||
214 | /** |
||
215 | * Set properties on the model. |
||
216 | * |
||
217 | * @param array $properties |
||
218 | * |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function withProperties(array $properties) |
||
227 | |||
228 | /** |
||
229 | * Set attributes on the model. |
||
230 | * |
||
231 | * @param array $properties |
||
232 | * |
||
233 | * @return $this |
||
234 | */ |
||
235 | public function withAttributes(array $properties) |
||
239 | |||
240 | /** |
||
241 | * Add the given additional headers when copying the file to a remote filesystem. |
||
242 | * |
||
243 | * @param array $customRemoteHeaders |
||
244 | * |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function addCustomHeaders(array $customRemoteHeaders) |
||
253 | |||
254 | /** |
||
255 | * Set the target media collection to default. |
||
256 | * Will also start the import process. |
||
257 | * |
||
258 | * @param string $collectionName |
||
259 | * @param string $diskName |
||
260 | * |
||
261 | * @return Media |
||
262 | * |
||
263 | * @throws FileDoesNotExist |
||
264 | * @throws FileCannotBeAdded |
||
265 | */ |
||
266 | public function toMediaLibrary(string $collectionName = 'default', string $diskName = '') |
||
270 | |||
271 | /** |
||
272 | * Set the target media collection to default. |
||
273 | * Will also start the import process. |
||
274 | * |
||
275 | * @param string $collectionName |
||
276 | * @param string $diskName |
||
277 | * |
||
278 | * @return Media |
||
279 | * |
||
280 | * @throws FileDoesNotExist |
||
281 | * @throws FileCannotBeAdded |
||
282 | */ |
||
283 | public function toMediaLibraryOnDisk(string $collectionName = 'default', string $diskName = '') |
||
287 | |||
288 | /** |
||
289 | * Set the collection name where to import the file. |
||
290 | * Will also start the import process. |
||
291 | * |
||
292 | * @param string $collectionName |
||
293 | * @param string $diskName |
||
294 | * |
||
295 | * @return Media |
||
296 | * |
||
297 | * @throws FileDoesNotExist |
||
298 | * @throws FileCannotBeAdded |
||
299 | */ |
||
300 | public function toCollection(string $collectionName = 'default', string $diskName = '') |
||
304 | |||
305 | public function toCollectionOnCloudDisk(string $collectionName = 'default') |
||
309 | |||
310 | /** |
||
311 | * @param string $collectionName |
||
312 | * @param string $diskName |
||
313 | * |
||
314 | * @return \Spatie\MediaLibrary\Media |
||
315 | * |
||
316 | * @throws FileCannotBeAdded |
||
317 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
318 | */ |
||
319 | public function toCollectionOnDisk(string $collectionName = 'default', string $diskName = '') |
||
358 | |||
359 | /** |
||
360 | * Determine the disk to be used. |
||
361 | * |
||
362 | * @param string $diskName |
||
363 | * |
||
364 | * @return string |
||
365 | * |
||
366 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
367 | */ |
||
368 | protected function determineDiskName(string $diskName) |
||
380 | |||
381 | /** |
||
382 | * Sanitize the given file name. |
||
383 | * |
||
384 | * @param $fileName |
||
385 | * |
||
386 | * @return string |
||
387 | */ |
||
388 | protected function sanitizeFileName(string $fileName) : string |
||
392 | } |
||
393 |