src/Domain/Reporting/Symfony/EventSubscriber/Kernel/LogJournalSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Reporting\Symfony\EventSubscriber\Kernel;
  3. use App\Domain\Reporting\Dictionary\LogJournalActionDictionary;
  4. use App\Domain\Reporting\Symfony\EventSubscriber\Event\LogJournalEvent;
  5. use App\Infrastructure\ORM\Reporting\Repository\LogJournal;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class LogJournalSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var EntityManagerInterface
  12.      */
  13.     private $entityManager;
  14.     /**
  15.      * @var \App\Domain\Reporting\Repository\LogJournal
  16.      */
  17.     private $logJournalRepository;
  18.     public function __construct(EntityManagerInterface $entityManagerLogJournal $logJournalRepository)
  19.     {
  20.         $this->entityManager        $entityManager;
  21.         $this->logJournalRepository $logJournalRepository;
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             LogJournalEvent::class => ['saveLogJournal'],
  27.         ];
  28.     }
  29.     public function saveLogJournal(LogJournalEvent $event)
  30.     {
  31.         $logJournal $event->getLogJournal();
  32.         $this->entityManager->persist($logJournal);
  33.         $this->entityManager->flush();
  34.         if (LogJournalActionDictionary::DELETE === $logJournal->getAction()) {
  35.             $this->logJournalRepository->updateDeletedLog($event->getSubject());
  36.         }
  37.     }
  38. }