<?php
namespace App\EventSubscriber;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Event\IssueEvent;
/**
* This is a generic issue exception, which can be called by:
* $dispatcher = $this->get('event_dispatcher');
* $dispatcher->dispatch('iris.issue', \App\Event\IssueEvent);
* A new \App\Event\IssueEvent must be include a message in the construct
* The other optional parameters are
* - status (default: 'Generic Issue')
* - type (default: 'new', possible values are 'new' or 'resolved')
*/
class IssueEventSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
private $em;
public function __construct(
EntityManagerInterface $em
) {
$this->em = $em;
}
public static function getSubscribedEvents()
{
return array(
'iris.issue' => 'handleIssue',
);
}
public function handleIssue(IssueEvent $event) {
$this->em->persist($event->getIssue());
$this->em->flush();
}
}