mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 21:14:02 +00:00
Introduce integration events, drop
This commit is contained in:
parent
4342c5eb1b
commit
4c80ba78d3
2 changed files with 44 additions and 7 deletions
|
|
@ -59,13 +59,8 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
public function setTelescopeTags()
|
public function setTelescopeTags()
|
||||||
{
|
{
|
||||||
$original_callback = Telescope::$tagUsing;
|
Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) {
|
||||||
|
$tags = $this->integration('telescope', $entry);
|
||||||
Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) use ($original_callback) {
|
|
||||||
$tags = [];
|
|
||||||
if (! \is_null($original_callback)) {
|
|
||||||
$tags = $original_callback($entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\in_array('tenancy', request()->route()->middleware())) {
|
if (\in_array('tenancy', request()->route()->middleware())) {
|
||||||
$tags = \array_merge($tags, [
|
$tags = \array_merge($tags, [
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,13 @@ trait TenantManagerEvents
|
||||||
'ended' => [],
|
'ended' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration listeners.
|
||||||
|
*
|
||||||
|
* @var callable[][]
|
||||||
|
*/
|
||||||
|
protected $integrationListeners = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a listener that will be executed before tenancy is bootstrapped.
|
* Register a listener that will be executed before tenancy is bootstrapped.
|
||||||
*
|
*
|
||||||
|
|
@ -82,4 +89,39 @@ trait TenantManagerEvents
|
||||||
return $prevents->merge($listener($this) ?? []);
|
return $prevents->merge($listener($this) ?? []);
|
||||||
}, collect([]));
|
}, 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