ksfraser / event
PSR-14 compliant event system with extended listener management
v1.0.0
2025-11-24 06:25 UTC
Requires
- php: >=8.1
- psr/event-dispatcher: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2026-02-16 22:43:20 UTC
README
A PSR-14 compliant event system with extended listener management capabilities for PHP applications.
Features
- PSR-14 Compliance: Full compatibility with PSR-14 Event Dispatcher standard
- Extended Listener Management: Additional methods for advanced listener control
- Type-Safe: Full PHP 8.1+ type declarations and strict typing
- Singleton Pattern: Convenient global access through EventManager
- Plugin Support: Built-in support for plugin lifecycle events
Installation
composer require ksfraser/event
Basic Usage
use Ksfraser\Event\EventManager; use Ksfraser\Event\MyCustomEvent; // Dispatch an event EventManager::dispatchEvent(new MyCustomEvent($data)); // Add a listener EventManager::on('user.created', function($event) { // Handle user creation });
Creating Custom Events
<?php use Ksfraser\Event\Event; class UserCreatedEvent extends Event { public function __construct( public readonly int $userId, public readonly string $email ) {} }
Advanced Listener Management
use Ksfraser\Event\EventManager; // Add multiple listeners EventManager::on('order.processed', [$orderService, 'sendConfirmation']); EventManager::on('order.processed', 'sendOrderNotification'); // Get listener provider for advanced management $listenerProvider = EventManager::getInstance()->getListenerProvider();
Requirements
- PHP 8.1+
- PSR-14 Event Dispatcher interface
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the GPL v3 License.