Symfony 2: Disable Doctrine event listener in ContainerAwareCommand(Symfony 2:在 ContainerAwareCommand 中禁用 Doctrine 事件监听器)
问题描述
我正在使用在配置文件中注册的几个 Doctrine 侦听器进行一些自动更新(created_on、updated_on 时间戳等).目前我已经实现了额外的功能,需要将准备好的值存储在数据库中以便于搜索.
I am using several Doctrine listeners registered in configuration file for some automatic updates (created_on, updated_on timestamps etc.). Currently I have implemented additional functionality that requires stashing prepared values in the database for easier searching.
我正在考虑更新 Symfony 命令来准备这些值,而不是 SQL 更新脚本(实际上,任何类型的更改或更新值的方式都需要运行这个单个命令).不过这也会触发前面提到的 EventListeners.
I am thinking about update Symfony command that would prepare these values instead of SQL update script (actually any sort of change or update in the way the value is crated would than require just running this single command). However this would also trigger the EventListeners mentioned earlier.
有没有办法为单个命令禁用特定的 EventLister?
Is there a way how to disable particular EventLister for single Command?
推荐答案
这样的事情应该可以解决问题:
something like this should do the trick :
$searchedListener = null;
$em = $this->getDoctrine()->getManager();
foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
foreach ($listeners as $key => $listener) {
if ($listener instanceof ListenerClassYouLookFor) {
$searchedListener = $listener;
break 2;
}
}
}
if ($searchedListener) {
$evm = $em->getEventManager();
$evm->removeEventListener(array('onFlush'), $searchedListener);
}
else { //listener not found
}
这篇关于Symfony 2:在 ContainerAwareCommand 中禁用 Doctrine 事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony 2:在 ContainerAwareCommand 中禁用 Doctrine 事件监听器
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Laravel 仓库 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01