phpextra/event-manager

基于反射、注解和优先级队列的事件管理器

5.0.0 2019-03-26 15:51 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:23:41 UTC


README

Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality Code Coverage

它是如何工作的?

事件和监听器都是(标记)接口。事件支持继承。

示例

class UserLoginEvent implements Event
{
    public $userId;
}

class UserListener implements Listener
{
    /**
     * Acts on UserLoginEvent or it's descendants
     */
    public function onUserLogin(UserLoginEvent $event)
    {
        echo "User listener 1";
    }

    /**
     * Act on any event
     */
    public function onAnyEvent(Event $event)
    {
        echo "User listener 2";
    }
}

$manager = new EventManager();
$manager->add(new UserListener());
$manager->emit(new UserLoginEvent($user));

结果

> User listener 1
> User listener 2

安装(Composer)

composer require phpextra/event-manager:5.*

运行测试

composer tests

运行 php-cs-fixer

composer fix

贡献

所有代码贡献必须通过 pull request 进行。Fork 项目,创建功能分支,然后发送给我 pull request。为了确保代码库的一致性,你应该确保代码遵循 编码标准。如果你想帮忙,请查看 问题列表

作者

Jacek Kobus - kobus.jacek@gmail.com