| 1 | <?php |
||
| 7 | class BackupPath |
||
| 8 | { |
||
| 9 | /** @var array */ |
||
| 10 | protected static $allowedMimeTypes = [ |
||
| 11 | 'application/zip', |
||
| 12 | 'application/x-zip', |
||
| 13 | 'application/x-gzip', |
||
| 14 | ]; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param \Illuminate\Contracts\Filesystem\Filesystem|null $disk |
||
| 18 | * @param string $path |
||
| 19 | * |
||
| 20 | * @return bool |
||
| 21 | */ |
||
| 22 | public function isBackupFile($disk, string $path) : bool |
||
| 23 | { |
||
| 24 | return $this->hasZipExtension($path) ?: $this->hasAllowedMimeType($disk, $path); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $path |
||
| 29 | * |
||
| 30 | * @return bool |
||
| 31 | */ |
||
| 32 | protected function hasZipExtension($path) |
||
| 33 | { |
||
| 34 | return pathinfo($path, PATHINFO_EXTENSION) === 'zip'; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param \Illuminate\Contracts\Filesystem\Filesystem|null $disk |
||
| 39 | * @param string $path |
||
| 40 | * |
||
| 41 | * @return bool |
||
| 42 | */ |
||
| 43 | protected function hasAllowedMimeType($disk, $path) |
||
| 44 | { |
||
| 45 | return in_array($this->mimeType($disk, $path), self::$allowedMimeTypes); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param \Illuminate\Contracts\Filesystem\Filesystem|null $disk |
||
| 50 | * @param string $path |
||
| 51 | * |
||
| 52 | * @return string|false |
||
| 53 | */ |
||
| 54 | protected function mimeType($disk, $path) |
||
| 67 | } |
||
| 68 |