From 387a10b918386876d937637405fd4e52438212ad Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Wed, 30 Nov 2022 10:22:01 +0500 Subject: [PATCH] use proper DI --- .../PrefixCacheTenancyBootstrapper.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php index dc9989b4..3db62c33 100644 --- a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php +++ b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php @@ -4,7 +4,8 @@ declare(strict_types=1); namespace Stancl\Tenancy\Bootstrappers; -use Illuminate\Cache\Repository; +use Illuminate\Cache\Repository as CacheRepository; +use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Facades\Cache; use Stancl\Tenancy\Contracts\TenancyBootstrapper; @@ -16,16 +17,17 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper protected string $storeName; public function __construct( - protected Application $app + protected Application $app, + protected Repository $config, ) { } public function bootstrap(Tenant $tenant): void { - $this->originalPrefix = $this->app['config']['cache.prefix']; - $this->storeName = $this->app['config']['cache.default']; + $this->originalPrefix = $this->config->get('cache.prefix'); + $this->storeName = $this->config->get('cache.default'); - $this->setCachePrefix($this->app['config']['tenancy.cache.prefix_base'] . $tenant->getTenantKey()); + $this->setCachePrefix($this->config->get('tenancy.cache.prefix_base') . $tenant->getTenantKey()); } public function revert(): void @@ -36,7 +38,7 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper protected function setCachePrefix(null|string $prefix): void { - $this->app['config']['cache.prefix'] = $prefix; + $this->config->set('cache.prefix', $prefix); $this->app['cache']->forgetDriver($this->storeName); @@ -48,7 +50,7 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper $this->app->forgetInstance('cache.store'); // Forget the cache repository in the container to cover some edge-cases - $this->app->forgetInstance(Repository::class); + $this->app->forgetInstance(CacheRepository::class); // It is needed when a call to the facade has been made before bootstrapping tenancy // The facade has its own cache, separate from the container