src/EventSubscriber/IssueEventSubscriber.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Doctrine\Bundle\DoctrineBundle\Registry;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use App\Event\IssueEvent;
  7. /**
  8.  * This is a generic issue exception, which can be called by:
  9.  *   $dispatcher = $this->get('event_dispatcher');
  10.  *   $dispatcher->dispatch('iris.issue', \App\Event\IssueEvent);
  11.  * A new \App\Event\IssueEvent must be include a message in the construct
  12.  * The other optional parameters are
  13.  * - status (default: 'Generic Issue')
  14.  * - type (default: 'new', possible values are 'new' or 'resolved')
  15.  */
  16. class IssueEventSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var EntityManagerInterface
  20.      */
  21.     private $em;
  22.     public function __construct(
  23.         EntityManagerInterface $em
  24.     ) {
  25.         $this->em $em;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return array(
  30.             'iris.issue' => 'handleIssue',
  31.         );
  32.     }
  33.     public function handleIssue(IssueEvent $event) {
  34.         $this->em->persist($event->getIssue());
  35.         $this->em->flush();
  36.     }
  37. }