From 20f109acef068ff6dc0941b8c0e18a3f75ae1151 Mon Sep 17 00:00:00 2001 From: Matthew Daly <450801+matthewbdaly@users.noreply.github.com> Date: Sun, 15 Nov 2020 15:38:18 +0000 Subject: [PATCH] Tidied up service provider a bit --- src/AzureStorageServiceProvider.php | 12 ++++-------- src/Exceptions/CacheAdapterNotInstalled.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/Exceptions/CacheAdapterNotInstalled.php diff --git a/src/AzureStorageServiceProvider.php b/src/AzureStorageServiceProvider.php index 012566e..57bf72e 100644 --- a/src/AzureStorageServiceProvider.php +++ b/src/AzureStorageServiceProvider.php @@ -10,11 +10,10 @@ use League\Flysystem\Filesystem; use League\Flysystem\Cached\CachedAdapter; use League\Flysystem\Cached\Storage\Memory as MemoryStore; +use Matthewbdaly\LaravelAzureStorage\Exceptions\CacheAdapterNotInstalled; use MicrosoftAzure\Storage\Blob\BlobRestProxy; use MicrosoftAzure\Storage\Common\Middlewares\RetryMiddleware; use MicrosoftAzure\Storage\Common\Middlewares\RetryMiddlewareFactory; -use RuntimeException; -use Throwable; /** * Service provider for Azure Blob Storage @@ -38,12 +37,9 @@ public function boot() $config['prefix'] ?? null ); - $cache = Arr::pull($config, 'cache'); - if ($cache) { - try { - class_exists(CachedAdapter::class); - } catch (Throwable $e) { - throw new RuntimeException("Caching requires the league/flysystem-cached-adapter to be installed."); + if ($cache = Arr::pull($config, 'cache')) { + if (!class_exists(CachedAdapter::class)) { + throw new CacheAdapterNotInstalled("Caching requires the league/flysystem-cached-adapter to be installed."); } $adapter = new CachedAdapter($adapter, $this->createCacheStore($cache)); diff --git a/src/Exceptions/CacheAdapterNotInstalled.php b/src/Exceptions/CacheAdapterNotInstalled.php new file mode 100644 index 0000000..a775558 --- /dev/null +++ b/src/Exceptions/CacheAdapterNotInstalled.php @@ -0,0 +1,10 @@ +