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