mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 04:44:04 +00:00
Change bootstrappers namespace
This commit is contained in:
parent
b772590479
commit
1a8d150f2c
18 changed files with 26 additions and 26 deletions
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\TenancyBootstrappers;
|
||||
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Stancl\Tenancy\CacheManager as TenantCacheManager;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
||||
class CacheTenancyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
/** @var CacheManager */
|
||||
protected $originalCache;
|
||||
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function bootstrap(Tenant $tenant)
|
||||
{
|
||||
$this->resetFacadeCache();
|
||||
|
||||
$this->originalCache = $this->originalCache ?? $this->app['cache'];
|
||||
$this->app->extend('cache', function () {
|
||||
return new TenantCacheManager($this->app);
|
||||
});
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->resetFacadeCache();
|
||||
|
||||
$this->app->extend('cache', function () {
|
||||
return $this->originalCache;
|
||||
});
|
||||
|
||||
$this->originalCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This wouldn't be necessary, but is needed when a call to the
|
||||
* facade has been made prior to bootstrapping tenancy. The
|
||||
* facade has its own cache, separate from the container.
|
||||
*/
|
||||
public function resetFacadeCache()
|
||||
{
|
||||
Cache::clearResolvedInstances();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue