src/EventSubscriber/ClientSubscriber.php line 27
<?phpnamespace App\EventSubscriber;use App\Entity\Client;use App\Event\Client\ClientCreatedEvent;use App\Event\Client\ClientDeletedEvent;use App\Event\Client\ClientUpdatedEvent;use App\Service\NotificationService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class ClientSubscriber implements EventSubscriberInterface{public function __construct(private NotificationService $notificationService){}public static function getSubscribedEvents(): array{return [ClientCreatedEvent::class => 'onCreated',ClientUpdatedEvent::class => 'onUpdated',ClientDeletedEvent::class => 'onDeleted',];}public function onCreated(ClientCreatedEvent $event): void{$client = $event->getClient();if ($client instanceof Client) {$this->notificationService->notifyUser($client->getEstablishment()->getUser(),'Client ajouté',sprintf("Vous venez d'ajouter le client <strong>%s</strong>",$client->getName()),$client);}}public function onUpdated(ClientUpdatedEvent $event): void{$client = $event->getClient();if ($client instanceof Client) {$this->notificationService->notifyUser($client->getEstablishment()->getUser(),'Client modifié',sprintf("Vous venez de modifier le client <strong>%s</strong>",$client->getName()),$client);}}public function onDeleted(ClientDeletedEvent $event): void{$client = $event->getClient();if ($client instanceof Client) {$this->notificationService->notifyUser($client->getEstablishment()->getUser(),'Client supprimé',sprintf("Vous venez de supprimer le client <strong>%s</strong>",$client->getName()),$client);}}}