src/Services/WalletRedirect/WalletRedirectSubscriber.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Services\WalletRedirect;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\Cookie;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class WalletRedirectSubscriber implements EventSubscriberInterface
  8. {
  9.     public function saveSource(ResponseEvent $event): void
  10.     {
  11.         if (!$event->getRequest()->attributes->has(WalletRedirectService::SOURCE_ATTRIBUTE_NAME)) {
  12.             return;
  13.         }
  14.         $source $event->getRequest()->attributes->get(WalletRedirectService::SOURCE_ATTRIBUTE_NAME);
  15.         $cookie Cookie::create(WalletRedirectService::COOKIE_NAME)
  16.             ->withValue($source)
  17.             ->withExpires(strtotime("+1 year"));
  18.         $event->getResponse()->headers->setCookie($cookie);
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             KernelEvents::RESPONSE => 'saveSource'
  24.         ];
  25.     }
  26. }