src/EventSubscriber/RevisionSubscriber.php line 36

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\Revision\RevisionAcceptedEvent;
  4. use App\Event\Revision\RevisionRefusedEvent;
  5. use App\Service\NotificationService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class RevisionSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(private NotificationService $notificationService) {}
  10.     public static function getSubscribedEvents(): array
  11.     {
  12.         return [
  13.             RevisionAcceptedEvent::class => 'onRevisionAccepted',
  14.             RevisionRefusedEvent::class => 'onRevisionRefused',
  15.         ];
  16.     }
  17.     public function onRevisionAccepted(RevisionAcceptedEvent $revisionAcceptedEvent): void
  18.     {
  19.         $revision $revisionAcceptedEvent->getRevision();
  20.         $this->notificationService->notifyUser(
  21.             $revision->getAuthor(),
  22.             'Revision acceptée',
  23.             sprintf(
  24.                 "Votre pour <strong>%s</strong> a été acceptée",
  25.                 $revision->getContent()
  26.             ),
  27.             $revision
  28.         );
  29.     }
  30.     public function onRevisionRefused(RevisionRefusedEvent $revisionAcceptedEvent): void
  31.     {
  32.         $revision $revisionAcceptedEvent->getRevision();
  33.         $this->notificationService->notifyUser(
  34.             $revision->getAuthor(),
  35.             'Revision refusée',
  36.             sprintf(
  37.                 "Votre pour <strong>%s</strong> a été refusée :(",
  38.                 $revision->getContent()
  39.             ),
  40.             $revision
  41.         );
  42.     }
  43. }