API Events EventDispatcherInterface - evansims/openfga-php GitHub Wiki
Event dispatcher interface for handling domain events. The event dispatcher decouples event publishers from subscribers, allowing for flexible event handling and observability without tight coupling between business logic and infrastructure concerns.
Table of Contents
OpenFGA\Events
- EventDispatcher (implementation)
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(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