src/EventSubscriber/Order/SendOrderConfirmationMailSubsriber.php line 30

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\EventSubscriber\Order;
  12. use App\Entity\Order\Order;
  13. use App\Message\SendOrderEmailMessage;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\Messenger\MessageBusInterface;
  16. use Symfony\Component\Workflow\Event\Event;
  17. use Webmozart\Assert\Assert;
  18. class SendOrderConfirmationMailSubsriber implements EventSubscriberInterface
  19. {
  20.     public function __construct(
  21.         private MessageBusInterface $messageBus,
  22.     ) {
  23.     }
  24.     public function onEnter(Event $event): void
  25.     {
  26.         /** @var Order $order */
  27.         $order $event->getSubject();
  28.         Assert::isInstanceOf($orderOrder::class);
  29.         $orderId $order->getId();
  30.         if (null === $orderId) {
  31.             return;
  32.         }
  33.         $this->messageBus->dispatch(new SendOrderEmailMessage(
  34.             $orderId,
  35.             SendOrderEmailMessage::TYPE_CONFIRMATION,
  36.         ));
  37.     }
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             'workflow.order_production.entered.order_received' => 'onEnter',
  42.         ];
  43.     }
  44. }