EventManager
in package
Manages a simple publish/subscribe system based on regular expressions matching event names and running a fixed.
Table of Contents
- $g : Game
- __construct() : mixed
- getSubscriptions() : array<string|int, mixed>
- Return a list of existing subscriptions.
- publish() : EventContextData
- Publish an event. Will immediately cause handleEvent() to be called on all subscribed classes. This does not ensure any order in which the handlers are run.
- subscribe() : mixed
- Create a new event subscription, registering $class to receive the handleEvent() method every time an event matching $pattern is published.
- unsubscribe() : mixed
- Remove an event subscription, unregistering $class to receive the handleEvent() method when $pattern is published.
Properties
$g
private
Game
$g
Methods
__construct()
public
__construct(Game $g) : mixed
Parameters
- $g : Game
-
The game.
Return values
mixed —getSubscriptions()
Return a list of existing subscriptions.
public
getSubscriptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —publish()
Publish an event. Will immediately cause handleEvent() to be called on all subscribed classes. This does not ensure any order in which the handlers are run.
public
publish(string $event, EventContextData $contextData) : EventContextData
Parameters
- $event : string
-
The name of the event to publish.
- $contextData : EventContextData
-
The Data context
Return values
EventContextData —The changed data.
subscribe()
Create a new event subscription, registering $class to receive the handleEvent() method every time an event matching $pattern is published.
public
subscribe(string $pattern, string $class, string $library) : mixed
Parameters
- $pattern : string
-
Regular expression, in PHP format, to match against published event names.
- $class : string
-
Fully qualified class name, which implements the EventHandler interface, that will receive the handleEvent() method call when events matching $pattern are published.
- $library : string
-
Library this subscription belongs to.
Tags
Return values
mixed —unsubscribe()
Remove an event subscription, unregistering $class to receive the handleEvent() method when $pattern is published.
public
unsubscribe(string $pattern, string $class, string $library) : mixed
Parameters
- $pattern : string
-
Regular expression, in PHP format, to match against published event names.
- $class : string
-
Fully qualified class name.
- $library : string