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


Namespace

OpenFGA\Events


Source

View source code


Related Classes


Methods

addListener

public function addListener(string $eventType, callable $listener): void

Register an event listener for a specific event type.

View source


Parameters

Name Type Description
$eventType string The class name or identifier of the event to listen for
$listener callable

Returns

void


dispatch

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.

View source


Parameters

Name Type Description
$event EventInterface The event to dispatch

Returns

void


getListeners

public function getListeners(string $eventType): array<callable(object): void>

Get all registered listeners for a specific event type.

View source


Parameters

Name Type Description
$eventType string The event type to get listeners for

Returns

array&lt;callable(object): void&gt; — Array of listeners for the event type


hasListeners

public function hasListeners(string $eventType): bool

Check if there are any listeners for a specific event type.

View source


Parameters

Name Type Description
$eventType string The event type to check

Returns

bool — True if there are listeners, false otherwise


removeListeners

public function removeListeners(string $eventType): void

Remove all listeners for a specific event type.

View source


Parameters

Name Type Description
$eventType string The event type to clear listeners for

Returns

void

⚠️ **GitHub.com Fallback** ⚠️