<?php declare(strict_types=1);
namespace App\EventListener;
use App\Entity\ApidaeLog;
use App\Event\ApidaeEvent;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ApidaeSubscriber
* @package App\EventListener
*/
class ApidaeSubscriber implements EventSubscriberInterface
{
/** @var EntityManager|EntityManagerInterface */
private $entityManager;
/**
* UserSubscriber constructor.
*
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
ApidaeEvent::APIDAE_IMPORT_ERROR => ['importError'],
ApidaeEvent::APIDAE_UPDATE_ERROR => ['updateError'],
ApidaeEvent::APIDAE_IMPORT_INFO => ['importInfo'],
ApidaeEvent::APIDAE_UPDATE_INFO => ['updateInfo']
];
}
/**
* @param \App\Event\ApidaeEvent $event
*/
public function importError(ApidaeEvent $event)
{
$apiLog = new ApidaeLog();
$apiLog->setState(ApidaeEvent::APIDAE_IMPORT_ERROR);
$apiLog->setMessage($event->getMessage());
$this->entityManager->persist($apiLog);
$this->entityManager->flush();
}
/**
* @param \App\Event\ApidaeEvent $event
*/
public function updateError(ApidaeEvent $event)
{
$apiLog = new ApidaeLog();
$apiLog->setState(ApidaeEvent::APIDAE_UPDATE_ERROR);
$apiLog->setMessage($event->getMessage());
$apiLog->setCode($event->getCode());
$this->entityManager->persist($apiLog);
$this->entityManager->flush();
}
/**
* @param \App\Event\ApidaeEvent $event
*/
public function importInfo(ApidaeEvent $event)
{
$apiLog = new ApidaeLog();
$apiLog->setState(ApidaeEvent::APIDAE_IMPORT_INFO);
$apiLog->setMessage($event->getMessage());
$apiLog->setCode($event->getCode());
$this->entityManager->persist($apiLog);
$this->entityManager->flush();
}
/**
* @param \App\Event\ApidaeEvent $event
*/
public function updateInfo(ApidaeEvent $event)
{
$apiLog = new ApidaeLog();
$apiLog->setState(ApidaeEvent::APIDAE_UPDATE_INFO);
$apiLog->setMessage($event->getMessage());
$apiLog->setCode($event->getCode());
$this->entityManager->persist($apiLog);
$this->entityManager->flush();
}
}