src/EventSubscriber/OrderSubscriber.php line 61
<?phpnamespace App\EventSubscriber;use App\Entity\Order;use App\Event\Order\OrderCreatedEvent;use App\Event\Order\OrderCancelledEvent;use App\Event\Order\OrderInitEvent;use App\Event\Order\OrderUpdatedEvent;use App\Service\NotificationService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class OrderSubscriber implements EventSubscriberInterface{public function __construct(private readonly NotificationService $notificationService){}public static function getSubscribedEvents(): array{return [OrderCreatedEvent::class => 'onCreated',OrderInitEvent::class => 'onInit',OrderUpdatedEvent::class => 'onUpdated',OrderCancelledEvent::class => 'onCancelled',];}public function onCreated(OrderCreatedEvent $event): void{$order = $event->getOrder();if ($order instanceof Order) {$this->notificationService->notifyUser($order->getAuthor(),'Commande ajouté',sprintf("Vous venez d'ajouter la commande <strong>%s</strong>",$order->getReference()),$order);}}public function onInit(OrderInitEvent $event): void{$order = $event->getOrder();if ($order instanceof Order) {$this->notificationService->notifyUser($order->getAuthor(),'Commande initié',sprintf("Vous venez d'initier la commande <strong>%s</strong>",$order->getReference()),$order);}}public function onUpdated(OrderUpdatedEvent $event): void{$order = $event->getOrder();if ($order instanceof Order) {$this->notificationService->notifyUser($order->getAuthor(),'Commande modifié',sprintf("Vous venez de modifier la commande <strong>%s</strong>",$order->getReference()),$order);}}public function onCancelled(OrderCancelledEvent $event): void{$order = $event->getOrder();if ($order instanceof Order) {$this->notificationService->notifyUser($order->getAuthor(),'Commande annulé',sprintf("Vous venez d'annuler la commande <strong>%s</strong>",$order->getReference()),$order);}}}