1 | <?php |
||
18 | class FileAdder |
||
19 | { |
||
20 | /** @var \Illuminate\Database\Eloquent\Model subject */ |
||
21 | protected $subject; |
||
22 | |||
23 | /** @var \Spatie\MediaLibrary\Filesystem\Filesystem */ |
||
24 | protected $filesystem; |
||
25 | |||
26 | /** @var bool */ |
||
27 | protected $preserveOriginal = false; |
||
28 | |||
29 | /** @var string|\Symfony\Component\HttpFoundation\File\UploadedFile */ |
||
30 | protected $file; |
||
31 | |||
32 | /** @var array */ |
||
33 | protected $properties = []; |
||
34 | |||
35 | /** @var array */ |
||
36 | protected $customProperties = []; |
||
37 | |||
38 | /** @var string */ |
||
39 | protected $pathToFile; |
||
40 | |||
41 | /** @var string */ |
||
42 | protected $fileName; |
||
43 | |||
44 | /** @var string */ |
||
45 | protected $mediaName; |
||
46 | |||
47 | /** @var string */ |
||
48 | protected $diskName = ''; |
||
49 | |||
50 | /** @var null|callable */ |
||
51 | protected $fileNameSanitizer; |
||
52 | |||
53 | /** |
||
54 | * @param Filesystem $fileSystem |
||
55 | */ |
||
56 | public function __construct(Filesystem $fileSystem) |
||
64 | |||
65 | /** |
||
66 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
67 | * |
||
68 | * @return FileAdder |
||
69 | */ |
||
70 | public function setSubject(Model $subject) |
||
76 | |||
77 | /* |
||
78 | * Set the file that needs to be imported. |
||
79 | * |
||
80 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function setFile($file) |
||
114 | |||
115 | /** |
||
116 | * When adding the file to the media library, the original file |
||
117 | * will be preserved. |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function preservingOriginal() |
||
127 | |||
128 | /** |
||
129 | * Set the name of the media object. |
||
130 | * |
||
131 | * @param string $name |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function usingName(string $name) |
||
139 | |||
140 | /** |
||
141 | * Set the name of the media object. |
||
142 | * |
||
143 | * @param string $name |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function setName(string $name) |
||
153 | |||
154 | /** |
||
155 | * Set the name of the file that is stored on disk. |
||
156 | * |
||
157 | * @param string $fileName |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function usingFileName(string $fileName) |
||
165 | |||
166 | /** |
||
167 | * Set the name of the file that is stored on disk. |
||
168 | * |
||
169 | * @param string $fileName |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setFileName(string $fileName) |
||
179 | |||
180 | /** |
||
181 | * Set the metadata. |
||
182 | * |
||
183 | * @param array $customProperties |
||
184 | * |
||
185 | * @return $this |
||
186 | */ |
||
187 | public function withCustomProperties(array $customProperties) |
||
193 | |||
194 | /** |
||
195 | * Set properties on the model. |
||
196 | * |
||
197 | * @param array $properties |
||
198 | * |
||
199 | * @return $this |
||
200 | */ |
||
201 | public function withProperties(array $properties) |
||
207 | |||
208 | /** |
||
209 | * Set attributes on the model. |
||
210 | * |
||
211 | * @param array $properties |
||
212 | * |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function withAttributes(array $properties) |
||
219 | |||
220 | /** |
||
221 | * Add the given additional headers when copying the file to a remote filesystem. |
||
222 | * |
||
223 | * @param array $customRemoteHeaders |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | public function addCustomHeaders(array $customRemoteHeaders) |
||
233 | |||
234 | /** |
||
235 | * @param string $collectionName |
||
236 | * |
||
237 | * @return \Spatie\MediaLibrary\Media |
||
238 | * |
||
239 | * @throws FileCannotBeAdded |
||
240 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
241 | */ |
||
242 | public function toMediaCollectionOnCloudDisk(string $collectionName = 'default') |
||
246 | |||
247 | /** |
||
248 | * @param string $collectionName |
||
249 | * @param string $diskName |
||
250 | * |
||
251 | * @return \Spatie\MediaLibrary\Media |
||
252 | * |
||
253 | * @throws FileCannotBeAdded |
||
254 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
255 | */ |
||
256 | public function toMediaCollection(string $collectionName = 'default', string $diskName = '') |
||
289 | |||
290 | /** |
||
291 | * @param string $diskName |
||
292 | * |
||
293 | * @return string |
||
294 | * |
||
295 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
296 | */ |
||
297 | protected function determineDiskName(string $diskName) |
||
309 | |||
310 | /** |
||
311 | * @param $fileName |
||
312 | * |
||
313 | * @return string |
||
314 | */ |
||
315 | public function defaultSanitizer(string $fileName): string |
||
319 | |||
320 | /** |
||
321 | * Sanitize the fileName of the file using a callable. |
||
322 | * |
||
323 | * @param callable $fileNameSanitizer |
||
324 | * |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function sanitizingFileName(callable $fileNameSanitizer) |
||
333 | |||
334 | /** |
||
335 | * @param Media $media |
||
336 | */ |
||
337 | protected function attachMedia(Media $media) |
||
355 | |||
356 | /** |
||
357 | * @param HasMedia $model |
||
358 | * @param Media $media |
||
359 | * @param FileAdder $fileAdder |
||
360 | */ |
||
361 | protected function processMediaItem(HasMedia $model, Media $media, FileAdder $fileAdder) |
||
371 | } |
||
372 |