Download the PHP package parable-php/event without Composer
On this page you can find all versions of the php package parable-php/event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download parable-php/event
More information about parable-php/event
Files in parable-php/event
Package event
Short Description Parable Events is a simple event system
License MIT
Homepage https://github.com/parable-php/event
Informations about the package event
Parable Event
Parable Event is a straightforward event system that gets the job done.
Install
Php 8.0+ and composer are required.
Usage
Events are very simple. You add listeners to events (string
values) and then trigger an update with those events. You
can pass payloads into the trigger
calls, which will get passed to all relevant listeners.
The above example handily shows how to make scalar values modifiable by defining the parameter to the callable as a reference. Passing objects is generally advisable, but sometimes it's the in-place alteration of string values you need.
It's also possible to have a listener trigger on every single event.
The above example would simply log all events being updated. This can be handy for debugging, but can also be handy to listen to a specific subset of events by matching the event, rather than adding a single listener to all individual events.
API
listen(string $event, callable $$listener): void
- add listener to an eventlistenAll(callable $$listener): void
- add listener for all eventstrigger(string $event, $payload): void
- trigger an update for an event
Contributing
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at devvoh.com.
License
All Parable components are open-source software, licensed under the MIT license.