<?php
namespace App\Services\WalletRedirect;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class WalletRedirectSubscriber implements EventSubscriberInterface
{
public function saveSource(ResponseEvent $event): void
{
if (!$event->getRequest()->attributes->has(WalletRedirectService::SOURCE_ATTRIBUTE_NAME)) {
return;
}
$source = $event->getRequest()->attributes->get(WalletRedirectService::SOURCE_ATTRIBUTE_NAME);
$cookie = Cookie::create(WalletRedirectService::COOKIE_NAME)
->withValue($source)
->withExpires(strtotime("+1 year"));
$event->getResponse()->headers->setCookie($cookie);
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => 'saveSource'
];
}
}