Skip to content

Instantly share code, notes, and snippets.

@mrcmorales
Created June 17, 2014 10:05
Show Gist options
  • Save mrcmorales/dd49e9c83c7d5b2810b2 to your computer and use it in GitHub Desktop.
Save mrcmorales/dd49e9c83c7d5b2810b2 to your computer and use it in GitHub Desktop.
doctrine listener
class WouzeeEventListener
{
protected $eventDispatcher;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function getSubscribedEvents()
{
return array(
'postPersist',
'postFlush',
);
}
public function postPersist(EventArgs $args)
{
$entity = $args->getEntity;
if ($entity instanceof WouzeeEvent) {
$event = new GenericEvent($entity, array('type' => RabbitActionEnum::NEW_EVENT));
$this->dispatchEvent($event);
}
}
public function postFlush(PostFlushEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof WouzeeEvent) {
var_dump('entra post flush');
}
}
private function dispatchEvent(GenericEvent $event)
{
$this->eventDispatcher->dispatch(WouzeeEventEnum::NEW_EVENT, $event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment