mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 23:14:04 +00:00
[1.8.0] Add Telescope tags with tenant ids (#77)
This commit is contained in:
parent
8d8c177dac
commit
824ecfce48
3 changed files with 64 additions and 0 deletions
|
|
@ -18,6 +18,13 @@ trait TenantManagerEvents
|
|||
'ended' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* Integration listeners.
|
||||
*
|
||||
* @var callable[][]
|
||||
*/
|
||||
protected $integrationListeners = [];
|
||||
|
||||
/**
|
||||
* Register a listener that will be executed before tenancy is bootstrapped.
|
||||
*
|
||||
|
|
@ -82,4 +89,39 @@ trait TenantManagerEvents
|
|||
return $prevents->merge($listener($this) ?? []);
|
||||
}, collect([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback for an integration event.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function integrationEvent(string $name, callable $callback)
|
||||
{
|
||||
if (\array_key_exists($name, $this->integrationListeners)) {
|
||||
$this->integrationListeners[$name][] = $callback;
|
||||
} else {
|
||||
$this->integrationListeners[$name] = [$callback];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return callbacks for an integration event.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $arguments,...
|
||||
* @return callable[]
|
||||
*/
|
||||
public function integration(string $name, ...$arguments)
|
||||
{
|
||||
if ($arguments) {
|
||||
// If $arguments are supplied, execute all listeners with arguments.
|
||||
return \array_reduce($this->integrationListeners[$name] ?? [], function ($tags, $listener) use ($arguments) {
|
||||
return \array_merge($tags, $listener(...$arguments));
|
||||
}, []);
|
||||
}
|
||||
|
||||
return $this->integrationListeners[$name];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue