1 | <?php |
||
15 | class FileAdder |
||
16 | { |
||
17 | /** |
||
18 | * @var \Illuminate\Database\Eloquent\Model subject |
||
19 | */ |
||
20 | protected $subject; |
||
21 | |||
22 | /** |
||
23 | * @var Filesystem |
||
24 | */ |
||
25 | protected $fileSystem; |
||
26 | |||
27 | /** |
||
28 | * @var Repository |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $preserveOriginal = false; |
||
36 | |||
37 | /** |
||
38 | * @var string|\Symfony\Component\HttpFoundation\File\UploadedFile |
||
39 | */ |
||
40 | protected $file; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $properties = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $customProperties = []; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $pathToFile; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $fileName; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $mediaName; |
||
66 | |||
67 | /** |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $diskName = ''; |
||
71 | |||
72 | /** |
||
73 | * @param Filesystem $fileSystem |
||
74 | * @param Repository $config |
||
75 | */ |
||
76 | public function __construct(Filesystem $fileSystem, Repository $config) |
||
81 | |||
82 | /** |
||
83 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
84 | * |
||
85 | * @return FileAdder |
||
86 | */ |
||
87 | public function setSubject($subject) |
||
93 | |||
94 | /** |
||
95 | * Set the file that needs to be imported. |
||
96 | * |
||
97 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
98 | * |
||
99 | * @return $this |
||
100 | * |
||
101 | * @throws FileCannotBeImported |
||
102 | */ |
||
103 | public function setFile($file) |
||
133 | |||
134 | /** |
||
135 | * When adding the file to the media library, the original file |
||
136 | * will be preserved. |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function preservingOriginal() |
||
146 | |||
147 | /** |
||
148 | * Set the name of the media object. |
||
149 | * |
||
150 | * @param $name |
||
151 | * |
||
152 | * @return $this |
||
153 | */ |
||
154 | public function usingName($name) |
||
158 | |||
159 | /** |
||
160 | * Set the name of the media object. |
||
161 | * |
||
162 | * @param $name |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | public function setName($name) |
||
172 | |||
173 | /** |
||
174 | * Set the name of the file that is stored on disk. |
||
175 | * |
||
176 | * @param $fileName |
||
177 | * |
||
178 | * @return $this |
||
179 | */ |
||
180 | public function usingFileName($fileName) |
||
184 | |||
185 | /** |
||
186 | * Set the name of the file that is stored on disk. |
||
187 | * |
||
188 | * @param $fileName |
||
189 | * |
||
190 | * @return $this |
||
191 | */ |
||
192 | public function setFileName($fileName) |
||
198 | |||
199 | /** |
||
200 | * Set the metadata. |
||
201 | * |
||
202 | * @param array $customProperties |
||
203 | * |
||
204 | * @return $this |
||
205 | */ |
||
206 | public function withCustomProperties(array $customProperties) |
||
212 | |||
213 | /** |
||
214 | * Set properties on the model. |
||
215 | * |
||
216 | * @param array $properties |
||
217 | * |
||
218 | * @return $this |
||
219 | */ |
||
220 | public function withProperties(array $properties) |
||
226 | |||
227 | /** |
||
228 | * Set attributes on the model. |
||
229 | * |
||
230 | * @param array $properties |
||
231 | * |
||
232 | * @return $this |
||
233 | */ |
||
234 | public function withAttributes(array $properties) |
||
238 | |||
239 | /** |
||
240 | * Set the target media collection to default. |
||
241 | * Will also start the import process. |
||
242 | * |
||
243 | * @param string $collectionName |
||
244 | * @param string $diskName |
||
245 | * |
||
246 | * @return Media |
||
247 | * |
||
248 | * @throws FileDoesNotExist |
||
249 | * @throws FileTooBig |
||
250 | */ |
||
251 | public function toMediaLibrary($collectionName = 'default', $diskName = '') |
||
255 | |||
256 | /** |
||
257 | * Set the target media collection to default. |
||
258 | * Will also start the import process. |
||
259 | * |
||
260 | * @param string $collectionName |
||
261 | * @param string $diskName |
||
262 | * |
||
263 | * @return Media |
||
264 | * |
||
265 | * @throws FileDoesNotExist |
||
266 | * @throws FileTooBig |
||
267 | */ |
||
268 | public function toMediaLibraryOnDisk($collectionName = 'default', $diskName = '') |
||
272 | |||
273 | /** |
||
274 | * Set the collection name where to import the file. |
||
275 | * Will also start the import process. |
||
276 | * |
||
277 | * @param string $collectionName |
||
278 | * @param string $diskName |
||
279 | * |
||
280 | * @return Media |
||
281 | * |
||
282 | * @throws FileDoesNotExist |
||
283 | * @throws FileTooBig |
||
284 | */ |
||
285 | public function toCollection($collectionName = 'default', $diskName = '') |
||
289 | |||
290 | /** |
||
291 | * @param string $collectionName |
||
292 | * @param string $diskName |
||
293 | * |
||
294 | * @return \Spatie\MediaLibrary\Media |
||
295 | * |
||
296 | * @throws \Spatie\MediaLibrary\Exceptions\FileDoesNotExist |
||
297 | * @throws \Spatie\MediaLibrary\Exceptions\FileTooBig |
||
298 | * @throws \Spatie\MediaLibrary\Exceptions\FilesystemDoesNotExist |
||
299 | */ |
||
300 | public function toCollectionOnDisk($collectionName = 'default', $diskName = '') |
||
335 | |||
336 | /** |
||
337 | * Determine the disk to be used. |
||
338 | * |
||
339 | * @param string $diskName |
||
340 | * |
||
341 | * @return string |
||
342 | * |
||
343 | * @throws FilesystemDoesNotExist |
||
344 | */ |
||
345 | protected function determineDiskName($diskName) |
||
357 | |||
358 | /** |
||
359 | * Sanitize the given file name. |
||
360 | * |
||
361 | * @param $fileName |
||
362 | * |
||
363 | * @return string |
||
364 | */ |
||
365 | protected function sanitizeFileName($fileName) |
||
369 | } |
||
370 |