1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:54:04 +00:00

event callback -> event listener

This commit is contained in:
Samuel Štancl 2019-09-11 19:18:53 +02:00
parent bf48764507
commit 958651099a
3 changed files with 10 additions and 14 deletions

View file

@ -39,8 +39,7 @@ class TelescopeTags implements FeatureProvider
return ($this->callback)($entry);
}
// todo name?
public function tagUsing(callable $callback)
public function setCallback(callable $callback)
{
$this->callback = $callback;
}

View file

@ -7,8 +7,6 @@ namespace Stancl\Tenancy;
use ArrayAccess;
use Stancl\Tenancy\Contracts\StorageDriver;
// todo tenant storage
/**
* @internal Class is subject to breaking changes in minor and patch versions.
*/

View file

@ -34,9 +34,8 @@ class TenantManagerv2
/** @var DatabaseManager */
protected $database;
// todo event "listeners" instead of "callbacks"
/** @var callable[][] */
protected $callbacks = [];
protected $listeners = [];
public function __construct(Application $app, ConsoleKernel $artisan, Contracts\StorageDriver $storage, DatabaseManager $database)
{
@ -241,30 +240,30 @@ class TenantManagerv2
}
/**
* Add an event callback.
* Add an event listener.
*
* @param string $name
* @param callable $callback
* @param callable $listener
* @return self
*/
public function eventCallback(string $name, callable $callback): self
public function eventListener(string $name, callable $listener): self
{
$this->eventCallbacks[$name] = $this->eventCallbacks[$name] ?? [];
$this->eventCallbacks[$name][] = $callback;
$this->eventListeners[$name] = $this->eventListeners[$name] ?? [];
$this->eventListeners[$name][] = $listener;
return $this;
}
/**
* Execute event callbacks.
* Execute event listeners.
*
* @param string $name
* @return string[]
*/
protected function event(string $name): array
{
return array_reduce($this->eventCalbacks[$name] ?? [], function ($prevented, $callback) {
$prevented = array_merge($prevented, $callback($this) ?? []);
return array_reduce($this->eventCalbacks[$name] ?? [], function ($prevented, $listener) {
$prevented = array_merge($prevented, $listener($this) ?? []);
return $prevented;
}, []);