src/EventSubscriber/ArticleDepartmentSubscriber.php line 46
<?phpnamespace App\EventSubscriber;use App\Entity\ArticleDepartment;use App\Event\ArticleDepartment\ArticleDepartmentDeletedEvent;use App\Event\ArticleDepartment\ArticleDepartmentUpdatedEvent;use App\Event\ArticleDepartment\ArticleDepartmentCreatedEvent;use App\Service\NotificationService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class ArticleDepartmentSubscriber implements EventSubscriberInterface{public function __construct(private readonly NotificationService $notificationService){}public static function getSubscribedEvents(): array{return [ArticleDepartmentCreatedEvent::class => 'onCreated',ArticleDepartmentUpdatedEvent::class => 'onUpdated',ArticleDepartmentDeletedEvent::class => 'onDeleted',];}public function onCreated(ArticleDepartmentCreatedEvent $event): void{$article = $event->getArticle();//if ($article instanceof ArticleDepartment) {$this->notificationService->notifyUser($article->getAuthor(),'Article ajouté au département',sprintf("Vous venez d'ajouter l'article <strong>%s</strong> au département <strong>%s</strong>",$article->getName(),$article->getDepartment()),$article);// }}public function onUpdated(ArticleDepartmentUpdatedEvent $event): void{$article = $event->getArticle();$this->notificationService->notifyUser($article->getAuthor(),'Article du département modifié',sprintf("Vous venez de modifier l'article <strong>%s</strong> du département <strong>%s</strong>",$article->getName(),$article->getDepartment()),$article);}public function onDeleted(ArticleDepartmentDeletedEvent $event): void{$article = $event->getArticle();$this->notificationService->notifyUser($article->getAuthor(),'Article retiré du département',sprintf("Vous venez de retirer l'article <strong>%s</strong> du département <strong>%s</strong>",$article->getName(),$article->getDepartment()),$article);}}