https://github.com/ghostwriter/event-dispatcher
Event Dispatcher implementation.
https://github.com/ghostwriter/event-dispatcher
event-dispatcher ghostwriter
Last synced: about 2 months ago
JSON representation
Event Dispatcher implementation.
- Host: GitHub
- URL: https://github.com/ghostwriter/event-dispatcher
- Owner: ghostwriter
- License: bsd-3-clause
- Created: 2021-11-24T15:08:50.000Z (over 4 years ago)
- Default Branch: 6.0.x
- Last Pushed: 2026-04-10T18:49:42.000Z (2 months ago)
- Last Synced: 2026-04-10T20:26:16.074Z (2 months ago)
- Topics: event-dispatcher, ghostwriter
- Language: PHP
- Homepage: https://github.com/ghostwriter/event-dispatcher
- Size: 81 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Event Dispatcher
[](https://github.com/sponsors/ghostwriter)
[](https://github.com/ghostwriter/event-dispatcher/actions/workflows/automation.yml)
[](https://www.php.net/supported-versions)
[](https://packagist.org/packages/ghostwriter/event-dispatcher)
Provides an Event Dispatcher implementation for PHP.
## Installation
You can install the package via composer:
``` bash
composer require ghostwriter/event-dispatcher
```
### Star ⭐️ this repo if you find it useful
You can also star (🌟) this repo to find it easier later.
### Usage
Registering and dispatching an Event Listener.
```php
use Ghostwriter\EventDispatcher\EventDispatcher;
use Ghostwriter\EventDispatcher\ListenerProvider;
// Create an event class
final class ExampleEvent
{
}
// Create an Event Listener
final class ExampleEventListener
{
public function __invoke(ExampleEvent $event): void
{
// Handle the event, e.g., print the event class name
// echo $event::class;
}
}
// Create a ListenerProvider
$listenerProvider = ListenerProvider::new(); // or new ListenerProvider(Container::getInstance())
// Bind the Listener to the Event
$listenerProvider->listen(ExampleEvent::class, ExampleEventListener::class);
// Create an EventDispatcher
$dispatcher = EventDispatcher::new($listenerProvider); // or new EventDispatcher($listenerProvider)
// Dispatch the Event.
$event = $dispatcher->dispatch(new ExampleEvent());
// Assert the Event is the same as the dispatched Event
assert($event instanceof ExampleEvent);
```
### Changelog
Please see [CHANGELOG.md](./CHANGELOG.md) for more information what has changed recently.
### Security
If you discover any security related issues, please email `nathanael.esayeas@protonmail.com` or create a [Security Advisory](https://github.com/ghostwriter/event-dispatcher/security/advisories/new) instead of using the issue tracker.
## License
The BSD-3-Clause. Please see [License File](./LICENSE) for more information.