mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 19:24:03 +00:00
[1.7.0] Add Events system (#93)
* Add TenantManagerEvents * Apply fixes from StyleCI * Fix typos, add tests * end() events
This commit is contained in:
parent
d7358c588c
commit
c1df467601
3 changed files with 149 additions and 0 deletions
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 = [
|
||||
'bootstrapping' => [],
|
||||
'bootstrapped' => [],
|
||||
'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 bootstrapped(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