mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 17:04:03 +00:00
DI app
This commit is contained in:
parent
c59a514490
commit
90c54ac733
1 changed files with 13 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Illuminate\Cache\Repository;
|
use Illuminate\Cache\Repository;
|
||||||
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
@ -14,10 +15,15 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
|
||||||
protected null|string $originalPrefix = null;
|
protected null|string $originalPrefix = null;
|
||||||
protected string $storeName;
|
protected string $storeName;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected Application $app
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
$this->originalPrefix = config('cache.prefix');
|
$this->originalPrefix = $this->app['config']['cache.prefix'];
|
||||||
$this->storeName = config('cache.default');
|
$this->storeName = $this->app['config']['cache.default'];
|
||||||
|
|
||||||
$this->setCachePrefix('tenant_id_' . $tenant->id);
|
$this->setCachePrefix('tenant_id_' . $tenant->id);
|
||||||
}
|
}
|
||||||
|
|
@ -32,20 +38,20 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected function setCachePrefix(string $prefix): void
|
protected function setCachePrefix(string $prefix): void
|
||||||
{
|
{
|
||||||
config()->set('cache.prefix', $prefix);
|
$this->app['config']['cache.prefix'] = $prefix;
|
||||||
|
|
||||||
app('cache')->forgetDriver($this->storeName);
|
$this->app['cache']->forgetDriver($this->storeName);
|
||||||
|
|
||||||
// This is important because the `CacheManager` will have the `$app['config']` array cached
|
// This is important because the `CacheManager` will have the `$app['config']` array cached
|
||||||
// with old prefixes on the `cache` instance. Simply calling `forgetDriver` only removes
|
// with old prefixes on the `cache` instance. Simply calling `forgetDriver` only removes
|
||||||
// the `$store` but doesn't update the `$app['config']`.
|
// the `$store` but doesn't update the `$app['config']`.
|
||||||
app()->forgetInstance('cache');
|
$this->app->forgetInstance('cache');
|
||||||
|
|
||||||
//This is important because the Cache Repository is using an old version of the CacheManager
|
//This is important because the Cache Repository is using an old version of the CacheManager
|
||||||
app()->forgetInstance('cache.store');
|
$this->app->forgetInstance('cache.store');
|
||||||
|
|
||||||
// Forget the cache repository in the container
|
// Forget the cache repository in the container
|
||||||
app()->forgetInstance(Repository::class);
|
$this->app->forgetInstance(Repository::class);
|
||||||
|
|
||||||
Cache::clearResolvedInstances();
|
Cache::clearResolvedInstances();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue