mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 23:14:03 +00:00
use proper DI
This commit is contained in:
parent
2901d0190c
commit
387a10b918
1 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue