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 simple event dispatcher that you can fit into the framework of your choice
License MIT
Informations about the package event-dispatcher
Event Dispatcher
A simple event dispatcher that you can fit into the framework of your choice.
⚖️ License
Licensed under the MIT license and is free for private or commercial projects.
✨ Introduction
Event Dispatcher is a lightweight, framework-agnostic library for implementing the observer pattern in PHP. It enables you to define events and attach listeners that react when those events are triggered - keeping your code clean, modular, and easy to extend.
📋 Prerequisites
Before you begin, ensure you have met the following requirements:
- PHP: Version 8.3 or higher.
- Composer: A dependency manager for PHP, used to install packages and autoload your code.
📦 Installation
Install the package via Composer:
🚀 Getting Started
1. Define Your Events
Create a class that implements AndrewDyer\EventDispatcher\Events\EventInterface
(or extend AbstractEvent
).
By default, the event name is the class name, but you can override it:
2. Create Your Listeners
Listeners must implement AndrewDyer\EventDispatcher\Listeners\ListenerInterface
(or extend AbstractListener
).
📖 Usage
Initialize the Dispatcher
Create a new instance of the event dispatcher:
Register a Listener
Attach a listener class to respond to a specific event:
💡 Tip: You can register multiple listeners for the same event name, and they will be executed in the order they were added.
Dispatch an Event
Trigger the event and notify all registered listeners:
🤝 Contributing
Found a bug or want to improve this package? Feel free to open a pull request or submit an issue.