https://github.com/commonphp/events
A powerful and flexible system to handle event-driven programming within PHP applications. It provides mechanisms for event registration, de-registration, triggering, and dynamic hook management.
https://github.com/commonphp/events
commonphp event-listeners event-management events hooks open-source php
Last synced: 4 days ago
JSON representation
A powerful and flexible system to handle event-driven programming within PHP applications. It provides mechanisms for event registration, de-registration, triggering, and dynamic hook management.
- Host: GitHub
- URL: https://github.com/commonphp/events
- Owner: commonphp
- License: mit
- Created: 2024-02-17T02:34:05.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-03-15T18:09:27.000Z (about 1 year ago)
- Last Synced: 2025-11-30T19:52:25.232Z (6 months ago)
- Topics: commonphp, event-listeners, event-management, events, hooks, open-source, php
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: license.md
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
# CommonPHP Events
A lightweight, PSR-14 compatible event dispatching library designed for simplicity and efficiency. It provides a global yet replaceable event dispatcher, supports prioritized listeners, and allows flexible event handling.
## Features
- **PSR-14 Compatible:** Implements the standard event dispatcher interface.
- **Simple Event Registration:** Easily register and dispatch events.
- **Prioritized Listeners:** Control execution order with priority levels.
- **Global or Dependency Injected:** Use globally or inject as needed.
- **Supports Stoppable Events:** Halt propagation when necessary.
## Installation
Install via Composer:
```bash
composer require comphp/events
```
## Usage
Create and dispatch events using the `EventDispatcher`.
```php
$username]);
}
}
// Initialize the dispatcher
$dispatcher = new EventDispatcher();
// Register a listener
$dispatcher->listen(UserRegisteredEvent::class, function (UserRegisteredEvent $event) {
echo "User registered: " . $event->getPayload()['username'] . "\n";
});
// Dispatch the event
$dispatcher->dispatch(new UserRegisteredEvent('Tim'));
```
## Examples
Additional example scripts are provided in the `examples/` directory, demonstrating different use cases of event dispatching.
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for a record of changes.
## Contributing
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to help out.
## Code of Conduct
This project is released under a Code of Conduct. Please review [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details.
## License
This project is licensed under the [MIT License](LICENSE.md). See the LICENSE file for more information.