mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:54:03 +00:00
Add event prevents, Tenant facade
This commit is contained in:
parent
1a88cad4d6
commit
4aa35322da
9 changed files with 187 additions and 97 deletions
|
|
@ -21,42 +21,55 @@ trait BootstrapsTenancy
|
|||
|
||||
public function bootstrap()
|
||||
{
|
||||
array_map(function ($listener) {
|
||||
$listener($this);
|
||||
}, $this->listeners['bootstrapping']);
|
||||
|
||||
$prevented = $this->event('bootstrapping');
|
||||
$this->initialized = true;
|
||||
|
||||
$this->switchDatabaseConnection();
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
if (! $prevented->contains('database')) {
|
||||
$this->switchDatabaseConnection();
|
||||
}
|
||||
$this->tagCache();
|
||||
$this->suffixFilesystemRootPaths();
|
||||
|
||||
array_map(function ($listener) {
|
||||
$listener($this);
|
||||
}, $this->listeners['bootstrapped']);
|
||||
if (! $prevented->contains('redis')) {
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $prevented->contains('cache')) {
|
||||
$this->tagCache();
|
||||
}
|
||||
|
||||
if (! $prevented->contains('filesystem')) {
|
||||
$this->suffixFilesystemRootPaths();
|
||||
}
|
||||
|
||||
$this->event('bootstrapped');
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
array_map(function ($listener) {
|
||||
$listener($this);
|
||||
}, $this->listeners['ending']);
|
||||
$prevented = $this->event('ending');
|
||||
|
||||
$this->initialized = false;
|
||||
|
||||
$this->disconnectDatabase();
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->resetPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
if (! $prevented->contains('database')) {
|
||||
$this->disconnectDatabase();
|
||||
}
|
||||
$this->untagCache();
|
||||
$this->resetFileSystemRootPaths();
|
||||
|
||||
array_map(function ($listener) {
|
||||
$listener($this);
|
||||
}, $this->listeners['ended']);
|
||||
if (! $prevented->contains('redis')) {
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->resetPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $prevented->contains('cache')) {
|
||||
$this->untagCache();
|
||||
}
|
||||
|
||||
if (! $prevented->contains('filesystem')) {
|
||||
$this->resetFileSystemRootPaths();
|
||||
}
|
||||
|
||||
$this->event('ended');
|
||||
}
|
||||
|
||||
public function switchDatabaseConnection()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue