felicity-php / felicity-events
PHP事件管理
1.0.0
2017-11-25 22:29 UTC
Requires
- felicity-php/felicity-datamodel: ^1.0
- roave/security-advisories: dev-master
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2024-09-15 04:10:44 UTC
README
Felicity events 提供了一种注册事件监听器和触发事件的方式
用法
使用静态 on
方法注册事件,或者如果通过依赖注入传递 EventManager::getInstance()
,则使用 onEvent
方法。
<?php use felicity\events\EventManager; use felicity\events\models\EventModel; $demoFunction = function (EventModel $model) { // ...do stuff // Event may send params on $model->params // Pass data back on $model->eventData // Stop other listeners on this event from running by // setting $model->stopEventProcessing = true // If the sender supports it, tell sender whether it should perform // its action with $model->performAction = false }; EventManager::on('myEvent', $demoFunction); // Supports any callable
使用静态 call
方法调用事件,或者如果通过依赖注入传递 EventManager::getInstance()
,则使用 callEvent
方法。
<?php use felicity\events\EventManager; use felicity\events\models\EventModel; $eventModel = new EventModel([ 'sender' => $this, 'params' => [ 'whatever' => 'you want to send', ], ]); EventManager::call('myEvent', $eventModel);
许可证
版权所有 2017 BuzzingPixel, LLC
根据 Apache 许可证 2.0 版(“许可证”);除非符合许可证规定,否则不得使用此文件。您可以在 https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本。
除非适用法律要求或书面同意,否则在许可证下分发的软件按“现状”分发,不提供任何明示或暗示的保证或条件。有关许可证的权限和限制的具体语言,请参阅许可证。