Download the PHP package devco/event-emitter without Composer
On this page you can find all versions of the php package devco/event-emitter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devco/event-emitter
More information about devco/event-emitter
Files in devco/event-emitter
Package event-emitter
Short Description Port of NodeJSs EventEmitter to PHP 5.4 using traits
License MIT
Homepage https://github.com/christopherobin/EventEmitter
Informations about the package event-emitter
EventEmitter
This is a direct port of the EventEmitter class from node.js using PHP 5.4 traits.
Why PHP 5.4?
Due to the nature of the EventEmitter functionnality, using simple extends sounds like the wrong way to deal with it as it is a set of functionnality to add to an existing class instead of your class extending the functionnalities of EventEmitter. As such traits are the best way to implement this kind of functionnality and those are only available to PHP 5.4+.
How to Use
API
-
setMaxListeners(int)
Set the maximum listeners allowed by events, default is 10. Adding too many listeners to a same event on the same object will make fireing events slower and slower, just up this limit if needed. -
emit(string[, mixed arg1, ...])
Emit an event, all arguments provided after the event name are sent to the callback as is. -
on(string, callable)
Register a callback for en event, every forms of callbacks are accepted (strings, arrays or closures). - addListener(string, callable)
Alias for on() -
all(callable)
Register a callback for en event, every forms of callbacks are accepted (strings, arrays or closures). - once(string, callable)
Same thing as on() but the listener will only be called once. -
off(string, callable)
Removes a listener for this event. You need to provide the very same array or string, or if using a closure the same instance. - removeListener(string, callable)
Alias for off() -
removeAllListeners([string])
Removes all listeners from a given event, or all listeners from all events if no event provided. - getListeners(string)
Returns an array with the listeners for this event