src/Race/EventSubscriber/RaceAttendeesSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Race\EventSubscriber;
  3. use App\Race\Event\RaceAttendEvent;
  4. use App\Race\Event\RaceEvents;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Mercure\HubInterface;
  7. use Symfony\Component\Mercure\Update;
  8. class RaceAttendeesSubscriber implements EventSubscriberInterface
  9. {
  10.   public function __construct(
  11.     protected HubInterface $hub,
  12.     protected \Twig\Environment $twig
  13.   ) {
  14.   }
  15.   public static function getSubscribedEvents()
  16.   {
  17.     return [
  18.       RaceEvents::ATTEND => 'updateRaceAttendees',
  19.       RaceEvents::UNATTEND => 'updateRaceAttendees',
  20.     ];
  21.   }
  22.   public function updateRaceAttendees(RaceAttendEvent $event)
  23.   {
  24.     $html $this->twig->render('network/race/event/attend.stream.twig', ['event' => $event->race]);
  25.     $this->hub->publish(new Update($event->getTopic(), $html));
  26.   }
  27. }