src/EventListener/ApidaeSubscriber.php line 59

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\EventListener;
  3. use App\Entity\ApidaeLog;
  4. use App\Event\ApidaeEvent;
  5. use Doctrine\ORM\EntityManager;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * Class ApidaeSubscriber
  10.  * @package App\EventListener
  11.  */
  12. class ApidaeSubscriber implements EventSubscriberInterface
  13. {
  14.     /** @var EntityManager|EntityManagerInterface */
  15.     private $entityManager;
  16.     /**
  17.      * UserSubscriber constructor.
  18.      *
  19.      * @param EntityManagerInterface $entityManager
  20.      */
  21.     public function __construct(EntityManagerInterface $entityManager)
  22.     {
  23.         $this->entityManager $entityManager;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             ApidaeEvent::APIDAE_IMPORT_ERROR    => ['importError'],
  32.             ApidaeEvent::APIDAE_UPDATE_ERROR    => ['updateError'],
  33.             ApidaeEvent::APIDAE_IMPORT_INFO     => ['importInfo'],
  34.             ApidaeEvent::APIDAE_UPDATE_INFO     => ['updateInfo']
  35.         ];
  36.     }
  37.     /**
  38.      * @param \App\Event\ApidaeEvent $event
  39.      */
  40.     public function importError(ApidaeEvent $event)
  41.     {
  42.         $apiLog = new ApidaeLog();
  43.         $apiLog->setState(ApidaeEvent::APIDAE_IMPORT_ERROR);
  44.         $apiLog->setMessage($event->getMessage());
  45.         $this->entityManager->persist($apiLog);
  46.         $this->entityManager->flush();
  47.     }
  48.     /**
  49.      * @param \App\Event\ApidaeEvent $event
  50.      */
  51.     public function updateError(ApidaeEvent $event)
  52.     {
  53.         $apiLog = new ApidaeLog();
  54.         $apiLog->setState(ApidaeEvent::APIDAE_UPDATE_ERROR);
  55.         $apiLog->setMessage($event->getMessage());
  56.         $apiLog->setCode($event->getCode());
  57.         $this->entityManager->persist($apiLog);
  58.         $this->entityManager->flush();
  59.     }
  60.     /**
  61.      * @param \App\Event\ApidaeEvent $event
  62.      */
  63.     public function importInfo(ApidaeEvent $event)
  64.     {
  65.         $apiLog = new ApidaeLog();
  66.         $apiLog->setState(ApidaeEvent::APIDAE_IMPORT_INFO);
  67.         $apiLog->setMessage($event->getMessage());
  68.         $apiLog->setCode($event->getCode());
  69.         $this->entityManager->persist($apiLog);
  70.         $this->entityManager->flush();
  71.     }
  72.     /**
  73.      * @param \App\Event\ApidaeEvent $event
  74.      */
  75.     public function updateInfo(ApidaeEvent $event)
  76.     {
  77.         $apiLog = new ApidaeLog();
  78.         $apiLog->setState(ApidaeEvent::APIDAE_UPDATE_INFO);
  79.         $apiLog->setMessage($event->getMessage());
  80.         $apiLog->setCode($event->getCode());
  81.         $this->entityManager->persist($apiLog);
  82.         $this->entityManager->flush();
  83.     }
  84. }