src/EventSubscriber/ReserveEventSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventSubscriber;
  4. use App\Entity\Reserve;
  5. use App\Entity\Transaction;
  6. use App\Event\ReserveCreateEvent;
  7. use App\Service\TransactionService;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class ReserveEventSubscriber implements EventSubscriberInterface
  11. {
  12.     private EntityManagerInterface $entityManager;
  13.     private TransactionService $transactionService;
  14.     public function __construct(EntityManagerInterface $entityManagerTransactionService $transactionService)
  15.     {
  16.         $this->entityManager $entityManager;
  17.         $this->transactionService $transactionService;
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             ReserveCreateEvent::NAME => 'createEvent',
  23.         ];
  24.     }
  25.     public function createEvent(ReserveCreateEvent $event): void
  26.     {
  27.         $reserve $event->getReserve();
  28.         $transactionRepository $this->entityManager->getRepository(Transaction::class);
  29.         $entity $transactionRepository->find($reserve->getId());
  30.         $this->transactionService->createReserveIncomeTransaction($event->getReserve());
  31.         $this->entityManager->flush();
  32.     }
  33. }