Download the PHP package andrewdyer/event-dispatcher without Composer
On this page you can find all versions of the php package andrewdyer/event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrewdyer/event-dispatcher
More information about andrewdyer/event-dispatcher
Files in andrewdyer/event-dispatcher
Package event-dispatcher
Short Description A framework-agnostic library for implementing the observer pattern through named events and registered listeners
License MIT
Homepage https://github.com/andrewdyer/event-dispatcher
Informations about the package event-dispatcher
Event Dispatcher
A framework-agnostic library for implementing the observer pattern through named events and registered listeners.
Introduction
This library lets events be defined as classes and listeners attached to them by name, with the dispatcher notifying every registered listener in the order they were added when an event is triggered. Listeners are kept fully decoupled from the code that raises the event, making it straightforward to extend application behaviour without modifying the originating logic, regardless of the framework in use.
Prerequisites
Installation
Getting Started
1. Define an event
Create a class that implements EventInterface, or extend AbstractEvent. By default, the event name is the short (unqualified) class name, but this can be overridden:
2. Create a listener
Create a class that implements ListenerInterface, or extend AbstractListener:
3. Set up the dispatcher
Instantiate EventDispatcher:
Usage
Registering a listener
Attach a listener to a specific event name via addListener():
Multiple listeners can be registered against the same event name; they are executed in the order they were added.
Dispatching an event
Trigger an event and notify all of its registered listeners via dispatch():
License
Licensed under the MIT licence and is free for private or commercial projects.