<?php declare(strict_types=1);
namespace App\Security\Subscriber;
use App\Service\PreferredTheme;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
class UpdateThemeSubscriber implements EventSubscriberInterface
{
private PreferredTheme $preferredTheme;
public function __construct(PreferredTheme $preferredTheme)
{
$this->preferredTheme = $preferredTheme;
}
public function onSuccess(LoginSuccessEvent $event): void
{
$request = $event->getRequest();
$response = $event->getResponse();
if (null !== $response) {
$mode = $this->preferredTheme->getPreferredTheme($request);
$this->preferredTheme->updatePreferredThemeCookie($response, $mode);
}
}
/**
* @return array<string, array<int|string, array<int|string, int|string>|int|string>|string>
*/
public static function getSubscribedEvents(): array
{
return [
LoginSuccessEvent::class => 'onSuccess',
];
}
}