Conditions | 3 |
Paths | 3 |
Total Lines | 23 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | public function upload(FileInterface $entity, File $file, string $field = 'filePath'): FileInterface |
||
28 | { |
||
29 | if (!($entity instanceof FileInterface)) { |
||
|
|||
30 | throw new \Exception('Invalid entity returned from FixtureFileUploader::upload factory'); |
||
31 | } |
||
32 | $tempFile = tmpfile(); |
||
33 | if (false === $tempFile) { |
||
34 | throw new \Exception('Could not create temporary file'); |
||
35 | } |
||
36 | $tempPath = stream_get_meta_data($tempFile)['uri']; |
||
37 | fclose($tempFile); |
||
38 | |||
39 | $fs = new Filesystem(); |
||
40 | $fs->copy($file->getRealPath(), $tempPath, true); |
||
41 | $uploadedFile = new UploadedFile( |
||
42 | $tempPath, |
||
43 | $file->getFilename(), |
||
44 | $file->getMimeType(), |
||
45 | null, |
||
46 | true |
||
47 | ); |
||
48 | $this->fileUploader->upload($entity, $field, $uploadedFile); |
||
49 | return $entity; |
||
50 | } |
||
52 |