slick / event
Simple PSR-14 event handling implementation.
Installs: 1 023
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.2
- ext-json: *
- psr/container: *
- psr/event-dispatcher: *
- ramsey/uuid: *
- slick/fswatch: *
Requires (Dev)
- phpspec/phpspec: 7.x-dev
- squizlabs/php_codesniffer: ^3.0@dev
This package is auto-updated.
Last update: 2025-06-17 17:38:37 UTC
README
Slick Event is a modern and lightweight PHP library that provides a clean, flexible, and PSR-14-compliant event dispatching system. Built for developers who value simplicity, testability, and performance, it allows you to decouple your application logic using event-driven architecture without the overhead of heavier frameworks.
Whether you're working with a microservice, a modular monolith, or a full-stack application, Slick Event integrates seamlessly and gives you the tools to manage domain events, listeners, and dispatchers with ease.
โจ Features
- โ PSR-14 compliant: Follows the PHP-FIG Event Dispatcher standard for interoperability.
- ๐ Synchronous event dispatching with support for multiple listeners.
- โ๏ธ Simple and intuitive API for registering and dispatching events.
- ๐งช Spec-driven development using PHPSpec ensures reliability and clean design.
- ๐งฉ Framework-agnostic: Use it in any PHP project, regardless of framework.
This package follows:
๐ Installation
Install via Composer:
composer require slick/event
๐งฉ Basic Usage
use Slick\Event\EventDispatcher; use Slick\Event\Event; $dispatcher = new EventDispatcher(); $dispatcher->listen(SomeEvent::class, function (SomeEvent $event) { // Handle event }); // Dispatch event $dispatcher->dispatch(new SomeEvent());
โ Usage
1. Define an Event and a Listener
namespace App\Domain\Event; final class UserWasRegistered { public function __construct(public string $email) {} }
namespace App\Application\Listener; use App\Domain\Event\UserWasRegistered; use Slick\Event\Application\Attribute\AsEventListener; #[AsEventListener(event: UserWasRegistered::class)] final class SendWelcomeEmail { public function __invoke(UserWasRegistered $event): void { // Send welcome email to $event->email } }
2. Set Up the ListenerProvider and Dispatcher
use Slick\Event\Infrastructure\AttributeListenerResolver; use Slick\Event\Infrastructure\AttributeListenerProvider; use Slick\Event\EventDispatcher; use App\YourContainer; $container = new YourContainer(); // PSR-11 compliant $resolver = new AttributeListenerResolver( __DIR__.'/src/Application/Listener', $container ); $provider = new AttributeListenerProvider($resolver); $dispatcher = new EventDispatcher($provider);
3. Dispatch the Event
$dispatcher->dispatch(new UserWasRegistered('user@example.com'));
All listeners discovered via #[AsEventListener]
will be automatically executed.
โ Testing
We use PHPSpec for unit testing.
Run tests with:
vendor/bin/phpspec run
or
composer test
๐ค Contributing
Please read our CONTRIBUTING.md guidelines.
๐ก Security
If you discover a security vulnerability, please email us at slick.framework@gmail.com instead of using the issue tracker.
๐ Credits
๐ License
This package is open-source software licensed under the MIT License.