<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use App\Service\Session\SessionService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
use Symfony\Component\Security\Http\SecurityEvents;
class SwitchUserSubscriber implements EventSubscriberInterface
{
public function __construct(
private SessionService $sessionService,
) {
}
public function onSwitchUser(SwitchUserEvent $event): void
{
$this->sessionService->switchUser($event->getTargetUser());
}
public static function getSubscribedEvents(): array
{
return [
// constant for security.switch_user
SecurityEvents::SWITCH_USER => 'onSwitchUser',
];
}
}