slick/event
最新稳定版本:v1.2.0
Composer 安装命令:
composer require slick/event
包简介
Simple PSR-14 event handling implementation.
README 文档
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.
统计信息
- 总下载量: 1.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-26