Total Complexity | 8 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class FilesDomain |
||
10 | { |
||
11 | protected $path, $disk; |
||
12 | |||
13 | 6 | public function __construct($path = null, $disk = 'local') |
|
14 | { |
||
15 | 6 | $this->path = $path === null ? config('filesystems.paths.default') : $path; |
|
16 | 6 | $this->disk = $disk; |
|
17 | 6 | } |
|
18 | |||
19 | 6 | public function saveFile(UploadedFile $file) |
|
20 | { |
||
21 | 6 | $fileName = $this->cleanFileName($file->getClientOriginalName()); |
|
22 | 6 | $fileName = $this->checkForDuplicate($fileName); |
|
23 | 6 | $file->storeAs($this->path, $fileName, $this->disk); |
|
24 | |||
25 | 6 | Log::debug('New File stored. Details - ', ['disk' => $this->disk, 'path' => $this->path, 'filename' => $fileName]); |
|
26 | 6 | return $fileName; |
|
27 | } |
||
28 | |||
29 | // Sanitize the filename to remove any illegal characters |
||
30 | 6 | protected function cleanFileName($name) |
|
31 | { |
||
32 | 6 | return preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $name); |
|
33 | } |
||
34 | |||
35 | // Check to see if the file already exists, if so append filename as needed |
||
36 | 6 | protected function checkForDuplicate($name) |
|
52 | } |
||
53 | } |
||
54 |