<?php
namespace App\EventSubscriber;
use App\Event\AppEvents;
use App\Event\FormEvent;
use App\ValueObject\ReviewStatuses;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class DeregistrationFormSubscriber
*/
class DeregistrationFormSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* DeregistrationFormSubscriber constructor.
*
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
AppEvents::DEREGISTRATION_FORM_CREATED => 'onDeregistrationFormCreated',
];
}
/**
* @param FormEvent $event
*/
public function onDeregistrationFormCreated(FormEvent $event)
{
$property = $event->getForm()->getProperty();
$event->getForm()->setStatus(ReviewStatuses::APPROVED);
$property->setDeregistrationDate(new DateTime());
$this->entityManager->flush();
}
}