<?php
namespace Stimactiv\LogBundle\EventSubscriber;
use Stimactiv\LogBundle\Model\SwitchUserLogManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
use Symfony\Component\Security\Http\SecurityEvents;
class SwitchUserSubscriber implements EventSubscriberInterface
{
private Security $security;
private SwitchUserLogManager $switchUserLogManager;
public function __construct(Security $security, SwitchUserLogManager $switchUserLogManager)
{
$this->security = $security;
$this->switchUserLogManager = $switchUserLogManager;
}
public function onSwitchUser(SwitchUserEvent $event): void
{
$this->switchUserLogManager->create($this->security->getUser(), $event->getTargetUser());
}
public static function getSubscribedEvents(): array
{
return [
// constant for security.switch_user
SecurityEvents::SWITCH_USER => 'onSwitchUser',
];
}
}