echo-fusion/eventmanager
最新稳定版本:v1.1
Composer 安装命令:
composer require echo-fusion/eventmanager
包简介
EventManager is a flexible and lightweight event handling system for PHP, allowing you to attach and trigger events with priorities and listeners.
关键字:
README 文档
README
EventManager is a flexible and lightweight event handling system for PHP, allowing you to attach and trigger events with priorities and listeners.
Installation
Install the package via Composer:
composer require echo-fusion/eventmanager
Requirements
The following versions of PHP are supported by this version.
- PHP 8.1
- PHP 8.2
- PHP 8.3
Usage
Here’s how to use the PluginManager to set up and run:
use EchoFusion\EventManager\EventManager; use EchoFusion\Contracts\EventManager\EventManagerInterface; // Create an instance of EventManager $eventManager = new EventManager(); // Define the first listener $listener1 = function (EventInterface $event) { echo "Listener 1: The event '" . $event->getName() . "' was triggered!\n"; }; // Define the second listener $listener2 = function (EventInterface $event) { echo "Listener 2: The event '" . $event->getName() . "' was triggered!\n"; }; // Attach both listeners to an event named 'user.register' $eventManager->attach('user.register', $listener1); $eventManager->attach('user.register', $listener2); // Create a new event $event = new class('user.register') extends BaseEvent { public function __construct(string $name) { $this->setName($name); } }; // Trigger the 'user.register' event, and both listeners will respond $eventManager->trigger($event);
Output:
Listener 1: The event 'user.register' was triggered! Listener 2: The event 'user.register' was triggered!
Testing
Testing includes PHPUnit and PHPStan (Level 7).
$ composer test
Credits
Developed and maintained by Amir Shadanfar.
Connect on LinkedIn.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-17