1
0
Fork 0
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:
Samuel Štancl 2019-08-19 21:11:55 +02:00 committed by GitHub
parent 8d8c177dac
commit 824ecfce48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 0 deletions

View file

@ -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];
}
}