UsePubSub
Table of Contents
- $subscribers : array<string|int, mixed>
- Subscribers.
- publish() : void
- Publish an event to all subscribers.
- subscribe() : void
- Subscribe to an event with a callback.
- unsubscribe() : void
- Unsubscribe a specific callback from an event.
Properties
$subscribers
Subscribers.
private
array<string|int, mixed>
$subscribers
= array()
Methods
publish()
Publish an event to all subscribers.
public
publish(string $event, mixed ...$args) : void
Parameters
- $event : string
-
The event name.
- $args : mixed
-
Arguments to pass to the callbacks.
Return values
void —subscribe()
Subscribe to an event with a callback.
public
subscribe(string $event, callable $callback) : void
Parameters
- $event : string
-
The event name.
- $callback : callable
-
The callback to execute when the event is published.
Return values
void —unsubscribe()
Unsubscribe a specific callback from an event.
public
unsubscribe(string $event, callable $callback) : void
Parameters
- $event : string
-
The event name.
- $callback : callable
-
The callback to remove.