1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-15 06:44:03 +00:00

Add and test DatabaseCacheBootstrapper

This commit is contained in:
lukinovec 2025-01-13 11:56:04 +01:00
parent 0e223e0484
commit 63b4efc028
3 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Config\Repository;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
use Illuminate\Cache\CacheManager;
class DatabaseCacheBootstrapper implements TenancyBootstrapper
{
public function __construct(
protected Repository $config,
protected CacheManager $cache,
protected string|null $originalConnection = null,
) {}
public function bootstrap(Tenant $tenant): void
{
$this->originalConnection = $this->config->get('cache.stores.database.connection');
$this->config->set('cache.stores.database.connection', 'tenant');
$this->cache->purge('database');
}
public function revert(): void
{
$this->config->set('cache.stores.database.connection', $this->originalConnection);
$this->cache->purge('database');
}
}