我正在使用 Symfony 2.3 和带有DoctrineExtensions的 Sonata Admin Bundle (由StofDoctrineExtensionsBundle启用)。我启用、配置并成功测试了 SoftDeleteable 和 Timestampable 组件。
现在,当我尝试使用 Symfony 标记服务添加另一个 Doctrine 事件订阅者时,似乎 softdeleteable 侦听器被禁用。
我的服务:
my.contact.listener.tag:
class: My\ContactBundle\EventListener\TagListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setTagManager, [ @fpn_tag.tag_manager ] ]
订户:
namespace My\ContactBundle\EventListener;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use DoctrineExtensions\Taggable\Taggable;
use FPN\TagBundle\Entity\TagManager;
class TagListener implements EventSubscriber
{
/**
* @var TagManager
*/
private $tagManager;
/**
* @param \FPN\TagBundle\Entity\TagManager $tagManager
*/
public function setTagManager($tagManager)
{
$this->tagManager = $tagManager;
}
/**
* Load tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->loadTagging($entity);
}
}
/**
* Save tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->saveTagging($entity);
}
}
/**
* Save tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->saveTagging($entity);
}
}
public function getSubscribedEvents()
{
return array(
'prePersist',
'preUpdate',
'postLoad',
);
}
}
在每个请求中,我都会遇到异常:
Listener "SoftDeleteableListener" was not added to the EventManager!
如果我禁用我的订阅者,问题就消失了。如何启用我的事件订阅者并拥有 softdeleteable?