src/EventDispatcher/InvoiceLoggingSubscribe.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventDispatcher;
  3. use App\Model\Invoice\Entity\Invoice\InvoiceActivityLog;
  4. use DateTime;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class InvoiceLoggingSubscribe implements EventSubscriberInterface
  8. {
  9.     private $em;
  10.     public function __construct(EntityManagerInterface $em)
  11.     {
  12.         $this->em $em;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return array(
  17.             InvoiceLoggingEvent::class => 'onInvoiceLogging'
  18.         );
  19.     }
  20.     public function onInvoiceLogging(InvoiceLoggingEvent $event)
  21.     {
  22.         $invoice_log = new InvoiceActivityLog();
  23.         $invoice_log->setStatus($event->getStatus());
  24.         $invoice_log->setInvoiceId($event->getInvoice());
  25.         $invoice_log->setChangeUserId($event->getUser());
  26.         $invoice_log->setChangeTime(new DateTime());
  27.         $this->em->persist($invoice_log);
  28.     }
  29. }