mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 10:14:04 +00:00
Add TenantManagerEvents
This commit is contained in:
parent
d7358c588c
commit
82237bd7f3
2 changed files with 80 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException;
|
||||||
|
|
||||||
trait BootstrapsTenancy
|
trait BootstrapsTenancy
|
||||||
{
|
{
|
||||||
|
use TenantManagerEvents;
|
||||||
|
|
||||||
public $originalSettings = [];
|
public $originalSettings = [];
|
||||||
/**
|
/**
|
||||||
* Was tenancy initialized/bootstrapped?
|
* Was tenancy initialized/bootstrapped?
|
||||||
|
|
@ -19,6 +21,10 @@ trait BootstrapsTenancy
|
||||||
|
|
||||||
public function bootstrap()
|
public function bootstrap()
|
||||||
{
|
{
|
||||||
|
array_map(function ($listener) {
|
||||||
|
$listener($this);
|
||||||
|
}, $this->listeners['boostrapping']);
|
||||||
|
|
||||||
$this->initialized = true;
|
$this->initialized = true;
|
||||||
|
|
||||||
$this->switchDatabaseConnection();
|
$this->switchDatabaseConnection();
|
||||||
|
|
@ -27,6 +33,10 @@ trait BootstrapsTenancy
|
||||||
}
|
}
|
||||||
$this->tagCache();
|
$this->tagCache();
|
||||||
$this->suffixFilesystemRootPaths();
|
$this->suffixFilesystemRootPaths();
|
||||||
|
|
||||||
|
array_map(function ($listener) {
|
||||||
|
$listener($this);
|
||||||
|
}, $this->listeners['boostrapped']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function end()
|
public function end()
|
||||||
|
|
|
||||||
70
src/Traits/TenantManagerEvents.php
Normal file
70
src/Traits/TenantManagerEvents.php
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Traits;
|
||||||
|
|
||||||
|
trait TenantManagerEvents
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Event listeners
|
||||||
|
*
|
||||||
|
* @var callable[][]
|
||||||
|
*/
|
||||||
|
protected $listeners = [
|
||||||
|
'boostrapping' => [],
|
||||||
|
'boostrapped' => [],
|
||||||
|
'ending' => [],
|
||||||
|
'ended' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener that will be executed before tenancy is bootstrapped.
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function bootstrapping(callable $callback)
|
||||||
|
{
|
||||||
|
$this->listeners['bootstrapping'][] = $callback;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener that will be executed after tenancy is bootstrapped.
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function boostrapped(callable $callback)
|
||||||
|
{
|
||||||
|
$this->listeners['bootstrapped'][] = $callback;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener that will be executed before tenancy is ended.
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function ending(callable $callback)
|
||||||
|
{
|
||||||
|
$this->listeners['ending'][] = $callback;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a listener that will be executed after tenancy is ended.
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function ended(callable $callback)
|
||||||
|
{
|
||||||
|
$this->listeners['ended'][] = $callback;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue