API Events EventDispatcher - evansims/openfga-php GitHub Wiki
Simple event dispatcher implementation. Manages event listeners and dispatches events to registered handlers. Supports event propagation control for stoppable events.
Table of Contents
OpenFGA\Events
- EventDispatcherInterface (interface)
public function addListener(string $eventType, callable $listener): void
Register an event listener for a specific event type.
Name | Type | Description |
---|---|---|
$eventType |
string |
The class name or identifier of the event to listen for |
$listener |
callable |
void
public function dispatch(OpenFGA\Events\EventInterface $event): void
Dispatch an event to all registered listeners. Calls all listeners registered for the given event's type. If an event is stoppable and a listener stops propagation, remaining listeners will not be called.
Name | Type | Description |
---|---|---|
$event |
EventInterface |
The event to dispatch |
void
public function getListeners(string $eventType): array<callable(object): void>
Get all registered listeners for a specific event type.
Name | Type | Description |
---|---|---|
$eventType |
string |
The event type to get listeners for |
array<
callable(object): void>
— Array of listeners for the event type
public function hasListeners(string $eventType): bool
Check if there are any listeners for a specific event type.
Name | Type | Description |
---|---|---|
$eventType |
string |
The event type to check |
bool
— True if there are listeners, false otherwise
public function removeListeners(string $eventType): void
Remove all listeners for a specific event type.
Name | Type | Description |
---|---|---|
$eventType |
string |
The event type to clear listeners for |
void