socketio-php / emitter
event emitter
v1.0
2020-03-18 10:04 UTC
Requires
- php: >=7.1.22
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-11-18 20:40:30 UTC
README
Event emitter component.
Installation
$ composer install socketio-php/emitter
Test
➜ emitter git:(master) ✗ php vendor/bin/phpunit tests/EmitterTest.php PHPUnit 7.5.20 by Sebastian Bergmann and contributors. .......... 10 / 10 (100%) Time: 24 ms, Memory: 4.00 MB OK (10 tests, 10 assertions)
API
Emitter#on(event, fn)
Register an event
handler fn
.
Emitter#once(event, fn)
Register a single-shot event
handler fn
,
removed immediately after it is invoked the
first time.
Emitter#off(event, fn)
- Pass
event
andfn
to remove a listener. - Pass
event
to remove all listeners on that event. - Pass nothing to remove all listeners on all events.
Emitter#emit(event, ...)
Emit an event
with variable option args.
Emitter#listeners(event)
Return an array of callbacks, or an empty array.
Emitter#hasListeners(event)
Check if this emitter has event
handlers.
License
MIT