logikostech / events
Phalcon PHP项目的事件辅助工具
v1.0.0
2017-04-08 19:40 UTC
Requires
- php: >=5.6
- ext-phalcon: >=2.0
Requires (Dev)
- phpunit/phpunit: ^4.0
- techpivot/phalcon-ci-installer: >=1.0
This package is auto-updated.
Last update: 2024-09-21 20:05:35 UTC
README
Logikos\Events\EventsAwareTrait
使用Phalcon\Events\EventsAwareInterface时的有用特性。主要功能是attachEventListener方法,如果在组件中使用时还没有使用EventsManager,它将添加一个并附加事件。这样,在设置\Phalcon\Di服务以及每个使用该组件的控制台或库时,可以根据情况自由地附加自己的事件。
用法
添加到类中
class foo implements \Phalcon\Events\EventsAwareInterface { use \Logikos\Events\EventsAwareTrait; }
轻松添加事件处理器
要监听所有事件,请传递null
$component->attachEventListener(null, function(\Phalcon\Events\Event $event, $component, $data=null) { switch ($event->getType()) { case 'beforeAction' : // ... break; case 'afterAction' : // ... break; } });
监听特定事件
$component->attachEventListener('beforeAction', function(\Phalcon\Events\Event $event, $component, $data=null) { // ... });