|
9 | 9 |
|
10 | 10 | class CreateLocalFile |
11 | 11 | { |
12 | | - use Dispatchable; |
| 12 | + use Dispatchable; |
13 | 13 |
|
14 | | - /** |
15 | | - * @var \Illuminate\Http\UploadedFile |
16 | | - */ |
17 | | - private $file; |
| 14 | + /** |
| 15 | + * @var \Illuminate\Http\UploadedFile |
| 16 | + */ |
| 17 | + private $file; |
18 | 18 |
|
19 | | - /** |
20 | | - * @var string |
21 | | - */ |
22 | | - private $reference; |
| 19 | + /** |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + private $reference; |
23 | 23 |
|
24 | | - public function __construct(string $reference, UploadedFile $file) |
25 | | - { |
26 | | - $this->reference = $reference; |
27 | | - $this->file = $file; |
28 | | - } |
| 24 | + public function __construct(string $reference, UploadedFile $file) |
| 25 | + { |
| 26 | + $this->reference = $reference; |
| 27 | + $this->file = $file; |
| 28 | + } |
29 | 29 |
|
30 | | - /** |
31 | | - * Execute the job. |
32 | | - * |
33 | | - * @return void |
34 | | - */ |
35 | | - public function handle() |
36 | | - { |
37 | | - $fileHandle = $this->file->openFile(); |
38 | | - $content = $fileHandle->fread($this->file->getSize()); |
| 30 | + /** |
| 31 | + * Execute the job. |
| 32 | + * |
| 33 | + * @return void |
| 34 | + */ |
| 35 | + public function handle() |
| 36 | + { |
| 37 | + $fileHandle = $this->file->openFile(); |
| 38 | + $content = $fileHandle->fread($this->file->getSize()); |
39 | 39 |
|
40 | | - $proxyFile = new ProxyFile([ |
41 | | - 'reference' => $this->reference, |
42 | | - 'type' => 'local', |
43 | | - 'filename' => $this->file->getClientOriginalName(), |
44 | | - 'mimetype' => $this->file->getClientMimeType(), |
45 | | - 'size' => $this->file->getSize(), |
46 | | - 'checksum' => sha1($content), |
47 | | - ]); |
48 | | - $proxyFile->save(); |
| 40 | + $proxyFile = new ProxyFile([ |
| 41 | + 'reference' => $this->reference, |
| 42 | + 'type' => 'local', |
| 43 | + 'filename' => $this->file->getClientOriginalName(), |
| 44 | + 'mimetype' => $this->file->getClientMimeType(), |
| 45 | + 'size' => $this->file->getSize(), |
| 46 | + 'checksum' => sha1($content), |
| 47 | + ]); |
| 48 | + $proxyFile->save(); |
49 | 49 |
|
50 | | - /** @var \App\LocalFile $localFile */ |
51 | | - $localFile = $proxyFile->localFile()->create([ |
52 | | - 'path' => uniqid('', true), |
53 | | - ]); |
| 50 | + /** @var \App\LocalFile $localFile */ |
| 51 | + $localFile = $proxyFile->localFile()->create([ |
| 52 | + 'path' => uniqid('', true), |
| 53 | + ]); |
54 | 54 |
|
55 | | - /** @var Filesystem|\Illuminate\Filesystem\FilesystemAdapter $filesystem */ |
56 | | - $filesystem = app(Filesystem::class); |
| 55 | + /** @var Filesystem|\Illuminate\Filesystem\FilesystemAdapter $filesystem */ |
| 56 | + $filesystem = app(Filesystem::class); |
57 | 57 |
|
58 | | - if (!$filesystem->exists('local')) { |
59 | | - $filesystem->makeDirectory('local'); |
60 | | - } |
| 58 | + if (! $filesystem->exists('local')) { |
| 59 | + $filesystem->makeDirectory('local'); |
| 60 | + } |
61 | 61 |
|
62 | | - $path = $localFile->getLocalStoragePath(); |
| 62 | + $path = $localFile->getLocalStoragePath(); |
63 | 63 |
|
64 | | - $fh = fopen($this->file->getRealPath(), 'rb'); |
65 | | - if ($filesystem->put($path, $fh)) { |
66 | | - $localFile->path = $path; |
67 | | - $localFile->save(); |
68 | | - } |
69 | | - fclose($fh); |
70 | | - } |
| 64 | + $fh = fopen($this->file->getRealPath(), 'rb'); |
| 65 | + if ($filesystem->put($path, $fh)) { |
| 66 | + $localFile->path = $path; |
| 67 | + $localFile->save(); |
| 68 | + } |
| 69 | + fclose($fh); |
| 70 | + } |
71 | 71 | } |
0 commit comments