1 | <?php |
||
17 | class FileAdder |
||
18 | { |
||
19 | /** @var \Illuminate\Database\Eloquent\Model subject */ |
||
20 | protected $subject; |
||
21 | |||
22 | /** @var \Spatie\MediaLibrary\Filesystem\Filesystem */ |
||
23 | protected $filesystem; |
||
24 | |||
25 | /** @var bool */ |
||
26 | protected $preserveOriginal = false; |
||
27 | |||
28 | /** @var string|\Symfony\Component\HttpFoundation\File\UploadedFile */ |
||
29 | protected $file; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $properties = []; |
||
33 | |||
34 | /** @var array */ |
||
35 | protected $customProperties = []; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $pathToFile; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $fileName; |
||
42 | |||
43 | /** @var string */ |
||
44 | protected $mediaName; |
||
45 | |||
46 | /** @var string */ |
||
47 | protected $diskName = ''; |
||
48 | |||
49 | /** |
||
50 | * @param Filesystem $fileSystem |
||
51 | */ |
||
52 | public function __construct(Filesystem $fileSystem) |
||
56 | |||
57 | /** |
||
58 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
59 | * |
||
60 | * @return FileAdder |
||
61 | */ |
||
62 | public function setSubject(Model $subject) |
||
68 | |||
69 | /* |
||
70 | * Set the file that needs to be imported. |
||
71 | * |
||
72 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function setFile($file) |
||
106 | |||
107 | /** |
||
108 | * When adding the file to the media library, the original file |
||
109 | * will be preserved. |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function preservingOriginal() |
||
119 | |||
120 | /** |
||
121 | * Set the name of the media object. |
||
122 | * |
||
123 | * @param string $name |
||
124 | * |
||
125 | * @return $this |
||
126 | */ |
||
127 | public function usingName(string $name) |
||
131 | |||
132 | /** |
||
133 | * Set the name of the media object. |
||
134 | * |
||
135 | * @param string $name |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function setName(string $name) |
||
145 | |||
146 | /** |
||
147 | * Set the name of the file that is stored on disk. |
||
148 | * |
||
149 | * @param string $fileName |
||
150 | * |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function usingFileName(string $fileName) |
||
157 | |||
158 | /** |
||
159 | * Set the name of the file that is stored on disk. |
||
160 | * |
||
161 | * @param string $fileName |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function setFileName(string $fileName) |
||
171 | |||
172 | /** |
||
173 | * Set the metadata. |
||
174 | * |
||
175 | * @param array $customProperties |
||
176 | * |
||
177 | * @return $this |
||
178 | */ |
||
179 | public function withCustomProperties(array $customProperties) |
||
185 | |||
186 | /** |
||
187 | * Set properties on the model. |
||
188 | * |
||
189 | * @param array $properties |
||
190 | * |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function withProperties(array $properties) |
||
199 | |||
200 | /** |
||
201 | * Set attributes on the model. |
||
202 | * |
||
203 | * @param array $properties |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function withAttributes(array $properties) |
||
211 | |||
212 | /** |
||
213 | * Add the given additional headers when copying the file to a remote filesystem. |
||
214 | * |
||
215 | * @param array $customRemoteHeaders |
||
216 | * |
||
217 | * @return $this |
||
218 | */ |
||
219 | public function addCustomHeaders(array $customRemoteHeaders) |
||
225 | |||
226 | /** |
||
227 | * @param string $collectionName |
||
228 | * |
||
229 | * @return \Spatie\MediaLibrary\Media |
||
230 | * |
||
231 | * @throws FileCannotBeAdded |
||
232 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
233 | */ |
||
234 | public function toMediaLibraryOnCloudDisk(string $collectionName = 'default') |
||
238 | |||
239 | /** |
||
240 | * @param string $collectionName |
||
241 | * @param string $diskName |
||
242 | * |
||
243 | * @return \Spatie\MediaLibrary\Media |
||
244 | * |
||
245 | * @throws FileCannotBeAdded |
||
246 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
247 | */ |
||
248 | public function toMediaLibrary(string $collectionName = 'default', string $diskName = '') |
||
288 | |||
289 | /** |
||
290 | * @param string $diskName |
||
291 | * |
||
292 | * @return string |
||
293 | * |
||
294 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
295 | */ |
||
296 | protected function determineDiskName(string $diskName) |
||
308 | |||
309 | /** |
||
310 | * @param $fileName |
||
311 | * |
||
312 | * @return string |
||
313 | */ |
||
314 | protected function sanitizeFileName(string $fileName) : string |
||
318 | } |
||
319 |