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:
parent
0e223e0484
commit
63b4efc028
3 changed files with 147 additions and 0 deletions
35
src/Bootstrappers/DatabaseCacheBootstrapper.php
Normal file
35
src/Bootstrappers/DatabaseCacheBootstrapper.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue