src/EventSubscriber/FacebookIdsSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Tracking\FacebookIds;
  4. use Exception;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. final readonly class FacebookIdsSubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(private FacebookIds $ids) {}
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             KernelEvents::REQUEST  => ['onRequest'10],
  16.             KernelEvents::RESPONSE => ['onResponse', -10],
  17.         ];
  18.     }
  19.     public function onRequest(RequestEvent $event): void
  20.     {
  21.         $req $event->getRequest();
  22.         $this->ids->resolve($req);
  23.     }
  24.     /**
  25.      * @throws Exception
  26.      */
  27.     public function onResponse(ResponseEvent $event): void
  28.     {
  29.         $this->ids->attachCookiesToResponse(
  30.             $event->getResponse(),
  31.             $event->getRequest()->isSecure()
  32.         );
  33.     }
  34. }