From 9a3e6a97daa4f25f006ea317f2cf2a05a06ce096 Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Fri, 18 Oct 2019 15:35:45 +0100 Subject: [PATCH] Fix the Filesystem manager's exception on unsupported driver --- .../Filesystem/FilesystemManager.php | 9 ++++---- tests/Filesystem/FilesystemManagerTest.php | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/Filesystem/FilesystemManagerTest.php diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index 8dd7f9f8ec26..f04d08149062 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -112,17 +112,18 @@ protected function get($name) protected function resolve($name) { $config = $this->getConfig($name); + $name = $config['driver'] ?? $name; - if (isset($this->customCreators[$config['driver']])) { + if (isset($this->customCreators[$name])) { return $this->callCustomCreator($config); } - $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; + $driverMethod = 'create'.ucfirst($name).'Driver'; if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($config); } else { - throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); + throw new InvalidArgumentException("Driver [{$name}] is not supported."); } } @@ -298,7 +299,7 @@ public function set($name, $disk) */ protected function getConfig($name) { - return $this->app['config']["filesystems.disks.{$name}"]; + return $this->app['config']["filesystems.disks.{$name}"] ?: []; } /** diff --git a/tests/Filesystem/FilesystemManagerTest.php b/tests/Filesystem/FilesystemManagerTest.php new file mode 100644 index 000000000000..81f9262b6414 --- /dev/null +++ b/tests/Filesystem/FilesystemManagerTest.php @@ -0,0 +1,23 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Driver [unsupported-disk] is not supported.'); + + $filesystem = new FilesystemManager(tap(new Application, function ($app) { + $app['config'] = ['filesystems.disks.unsupported-disk' => null]; + })); + + $filesystem->disk('unsupported-disk'); + } +}