EasyAdminBundle使用FOSUserBundle用户操纵器来创建&管理用户。我想捕获创建用户时使用的密码来更新后缀数据库。创建用户时,dev profiler不会显示已侦听任何FOSUserBundle事件。唯一的EasyAdminBundle事件是easy_admin.post_initialize
。 EasyAdminEvents
班级显示
/** @Event("Symfony\Component\EventDispatcher\GenericEvent") */
const POST_INITIALIZE = 'easy_admin.post_initialize';
但是一个事件监听器:
use Symfony\Component\EventDispatcher\GenericEvent;
...
public static function getSubscribedEvents()
{
return array(
GenericEvent::POST_INITIALIZE => 'onPostInitialize',
);
}
抛出:
致命错误:未捕获 Symfony \ Component \ Debug \ Exception \ FatalThrowableError:未定义的类 常量'POST_INITIALIZE'......
我认为答案是使用JavierEguiluz\Bundle\EasyAdminBundle\Event\EasyAdminEvents
事件而不是Symfony GenericEvent
。如在
use JavierEguiluz\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
...
public static function getSubscribedEvents()
{
return array(
EasyAdminEvents::POST_INITIALIZE => 'onPostInitialize',
);
}
...
//error occurs on the following line:
public function onPostInitialize(EasyAdminEvents $event)
{
...
}
然而,这样做给了我这个Catch 22:
必须是。的实例 JavierEguiluz \ Bundle \ EasyAdminBundle \ Event \ EasyAdminEvents,实例 给出“
的Symfony \ Component \ EventDispatcher \ GenericEvent
答案 0 :(得分:0)
所以最简单的答案是改变类型提示,如:
public function onPostInitialize(GenericEvent $event)
{
...
}