From 7a32adc48e2b341b076f7ea8ed3878f30b0bafbe Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 16 Dec 2020 11:13:50 -0500 Subject: [PATCH] Extend the cache driver within register As per https://github.com/laravel/docs/pull/6598 Closes #1721 --- src/Providers/CacheServiceProvider.php | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Providers/CacheServiceProvider.php b/src/Providers/CacheServiceProvider.php index 481fc20f1e..edc1f4c194 100644 --- a/src/Providers/CacheServiceProvider.php +++ b/src/Providers/CacheServiceProvider.php @@ -9,6 +9,16 @@ class CacheServiceProvider extends ServiceProvider { + /** + * Register any application services. + * + * @return void + */ + public function register() + { + $this->extendFileStore(); + } + /** * Bootstrap services. * @@ -16,7 +26,6 @@ class CacheServiceProvider extends ServiceProvider */ public function boot() { - $this->extendFileStore(); $this->macroRememberWithExpiration(); } @@ -27,17 +36,19 @@ public function boot() */ private function extendFileStore() { - Cache::extend('statamic', function () { - return Cache::repository(new FileStore( - $this->app['files'], - $this->app['config']['cache.stores.file']['path'] - )); - }); + $this->app->booting(function () { + Cache::extend('statamic', function () { + return Cache::repository(new FileStore( + $this->app['files'], + $this->app['config']['cache.stores.file']['path'] + )); + }); - if (config('cache.default') === 'file') { - config(['cache.stores.statamic' => ['driver' => 'statamic']]); - config(['cache.default' => 'statamic']); - } + if (config('cache.default') === 'file') { + config(['cache.stores.statamic' => ['driver' => 'statamic']]); + config(['cache.default' => 'statamic']); + } + }); } /**