src/Event/OrderIdSaveInSessionSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Event;
  4. use App\Component\Order\Events;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\EventDispatcher\GenericEvent;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. class OrderIdSaveInSessionSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var SessionInterface
  12.      */
  13.     private $session;
  14.     public function __construct(SessionInterface $session)
  15.     {
  16.         $this->session $session;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             Events::ORDER_CREATED => 'onOrderCreated',
  22.         ];
  23.     }
  24.     public function onOrderCreated(GenericEvent $event): void
  25.     {
  26.         $this->session->set('orderId'$event->getSubject()->getId());
  27.     }
  28. }