src/EventSubscriber/DeregistrationFormSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\AppEvents;
  4. use App\Event\FormEvent;
  5. use App\ValueObject\ReviewStatuses;
  6. use DateTime;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * Class DeregistrationFormSubscriber
  11.  */
  12. class DeregistrationFormSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var EntityManagerInterface
  16.      */
  17.     private $entityManager;
  18.     /**
  19.      * DeregistrationFormSubscriber constructor.
  20.      *
  21.      * @param EntityManagerInterface $entityManager
  22.      */
  23.     public function __construct(EntityManagerInterface $entityManager)
  24.     {
  25.         $this->entityManager $entityManager;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             AppEvents::DEREGISTRATION_FORM_CREATED => 'onDeregistrationFormCreated',
  34.         ];
  35.     }
  36.     /**
  37.      * @param FormEvent $event
  38.      */
  39.     public function onDeregistrationFormCreated(FormEvent $event)
  40.     {
  41.         $property $event->getForm()->getProperty();
  42.         $event->getForm()->setStatus(ReviewStatuses::APPROVED);
  43.         $property->setDeregistrationDate(new DateTime());
  44.         $this->entityManager->flush();
  45.     }
  46. }