|  | 
| 4 | 4 | 
 | 
| 5 | 5 | use Illuminate\Contracts\Foundation\Application; | 
| 6 | 6 | use Illuminate\Filesystem\FilesystemAdapter; | 
| 7 |  | -use Illuminate\Support\Arr; | 
| 8 | 7 | use Illuminate\Support\Facades\Storage; | 
| 9 | 8 | use Illuminate\Support\ServiceProvider; | 
| 10 |  | -use League\Flysystem\Filesystem; | 
| 11 |  | -use League\Flysystem\Local\LocalFilesystemAdapter; | 
| 12 |  | -use League\Flysystem\UnixVisibility\PortableVisibilityConverter; | 
| 13 |  | -use League\Flysystem\Visibility; | 
|  | 9 | +use InvalidArgumentException; | 
| 14 | 10 | use Swis\Flysystem\Encrypted\EncryptedFilesystemAdapter; | 
| 15 | 11 | use Swis\Laravel\Encrypted\Commands\ReEncryptFiles; | 
| 16 | 12 | use Swis\Laravel\Encrypted\Commands\ReEncryptModels; | 
| @@ -42,40 +38,28 @@ public function boot(): void | 
| 42 | 38 |     protected function setupStorageDriver(): void | 
| 43 | 39 |     { | 
| 44 | 40 |         Storage::extend( | 
| 45 |  | -            'local-encrypted', | 
| 46 |  | -            function (Application $app, array $config) { | 
| 47 |  | -                $visibility = PortableVisibilityConverter::fromArray( | 
| 48 |  | -                    $config['permissions'] ?? [], | 
| 49 |  | -                    $config['directory_visibility'] ?? $config['visibility'] ?? Visibility::PRIVATE | 
| 50 |  | -                ); | 
|  | 41 | +            'encrypted', | 
|  | 42 | +            (function (Application $app, array $config) { | 
|  | 43 | +                /** @var \Illuminate\Filesystem\FilesystemManager $this */ | 
|  | 44 | +                if (empty($config['disk'])) { | 
|  | 45 | +                    throw new InvalidArgumentException('Encrypted disk is missing "disk" configuration option.'); | 
|  | 46 | +                } | 
| 51 | 47 | 
 | 
| 52 |  | -                $links = ($config['links'] ?? null) === 'skip' | 
| 53 |  | -                    ? LocalFilesystemAdapter::SKIP_LINKS | 
| 54 |  | -                    : LocalFilesystemAdapter::DISALLOW_LINKS; | 
|  | 48 | +                $parent = $this->build( | 
|  | 49 | +                    is_string($config['disk']) ? $this->getConfig($config['disk']) : $config['disk'] | 
|  | 50 | +                ); | 
| 55 | 51 | 
 | 
| 56 | 52 |                 $adapter = new EncryptedFilesystemAdapter( | 
| 57 |  | -                    new LocalFilesystemAdapter( | 
| 58 |  | -                        $config['root'], | 
| 59 |  | -                        $visibility, | 
| 60 |  | -                        $config['lock'] ?? LOCK_EX, | 
| 61 |  | -                        $links | 
| 62 |  | -                    ), | 
|  | 53 | +                    $parent->getAdapter(), | 
| 63 | 54 |                     $app->make('encrypted-data.encrypter') | 
| 64 | 55 |                 ); | 
| 65 | 56 | 
 | 
| 66 |  | -                $driver = new Filesystem( | 
|  | 57 | +                return new FilesystemAdapter( | 
|  | 58 | +                    $this->createFlysystem($adapter, $parent->getConfig()), | 
| 67 | 59 |                     $adapter, | 
| 68 |  | -                    Arr::only($config, [ | 
| 69 |  | -                        'directory_visibility', | 
| 70 |  | -                        'disable_asserts', | 
| 71 |  | -                        'temporary_url', | 
| 72 |  | -                        'url', | 
| 73 |  | -                        'visibility', | 
| 74 |  | -                    ]) | 
|  | 60 | +                    $parent->getConfig() | 
| 75 | 61 |                 ); | 
| 76 |  | - | 
| 77 |  | -                return new FilesystemAdapter($driver, $adapter, $config); | 
| 78 |  | -            } | 
|  | 62 | +            })->bindTo(Storage::getFacadeRoot(), Storage::getFacadeRoot()) | 
| 79 | 63 |         ); | 
| 80 | 64 |     } | 
| 81 | 65 | } | 
0 commit comments