I create a subscriber and register a new service, what I do : https://gist.github.com/Draeli/2c591c16409a5664ae58
<?php
namespace My\BlogBundle\Listener;
use Doctrine\ORM\Events;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
class BlogArticleDetailListener implements EventSubscriberInterface
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
static public function getSubscribedEvents()
{
return array(
'doctrine.event_subscriber' => array(
array(Events::prePersist, 0),
array(Events::preUpdate, 0),
),
);
}
public function prePersist(FilterResponseEvent $event)
{
var_dump('prePersist');die;
}
public function preUpdate(FilterResponseEvent $event)
{
var_dump('preUpdate');die;
}
}
services:
my_blog.listener.blog_article_detail:
class: My\BlogBundle\Listener\BlogArticleDetailListener
arguments: ["@service_container"]
tags:
- { name: kernel.event_subscriber }
But in this case methods prePersist and preUpdate in spite of I persist objects, like if Doctrine didn't dispatch. Someone know what is strong in what I do ?
(For explanation, now I register only doctrine event but after I will register more from same place)