use EventDispatcher;
EventDispatcher::dispatch('user.login');
//你也可以在抛出事件时,塞入事件对象
EventDispatcher::dispatch('user.register', new \Event($user));
EventDispatcher::dispatch('user.register', new \UserEvent($user));
* @param eventName
\* @param listener 可以是一个callback方法或者一个继承于Listner的对象实例 \* @param priority 越大越早执行
* @param eventName
\* @param listener 可以是一个callback方法或者一个继承于Listner的对象实例
use EventDispatcher;
$listener = new KernalResponseListener();
//定义一个事件名称,触发的监听器,和一个重要指数
EventDispatcher::addListener('kernal.responese', $listener, 10);
EventDispatcher::removeListener('kernal.responese', $listener);
EventDispatcher::hasListeners('kernal.responese');
$subscriber = new TestSubscriber();
EventDispatcher::addSubscriber($subscriber);
EventDispatcher::hasListeners('test.start')
EventDispatcher::hasListeners('test.stop')
EventDispatcher::hasListeners('test.doing')
EventDispatcher::dispatch('test.start');
EventDispatcher::dispatch('test.stop');
EventDispatcher::dispatch('test.doing');
EventDispatcher::removeSubscriber($subscriber);