Symfony v3.3.4,Doctrine ORM v2.5.6
我已经为学说实体创建了一个事件订阅者:
AppBundle\EventListener\LivreSubscriber:
tags:
- { name: doctrine.event_subscriber }
效果很好!但很长一段时间我认为它不起作用,因为监听器没有在 debug:event-dispatcher 命令中列出:
$ docker-compose exec phpapp bin/console debug:event-dispatcher doctrine.event_subscriber
[WARNING] The event "doctrine.event_subscriber" does not have any registered listeners.
对于事件监听器来说也是一样的。 而且:监听器和订阅者都没有在 symfony 分析器(事件部分)中列出...... 所以它可以工作,但奇怪的是侦听器没有在调试工具中列出,不是吗?
你能告诉我你的项目是否有同样的行为......
此订阅者是学说订阅者,而不是 symfony。 Doctrine 使用自己的事件管理器,不与 symfony 事件调度程序连接。
console debug:event-dispatcher
仅列出在 symfony 事件调度程序中注册的订阅者。
php bin/console debug:container --tag=doctrine.event_subscriber
或
php bin/console debug:container --tag=doctrine.orm.entity_listener