vendor/stimactiv/log-bundle/src/EventSubscriber/SwitchUserSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace Stimactiv\LogBundle\EventSubscriber;
  3. use Stimactiv\LogBundle\Model\SwitchUserLogManager;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Security\Core\Security;
  6. use Symfony\Component\Security\Http\Event\SwitchUserEvent;
  7. use Symfony\Component\Security\Http\SecurityEvents;
  8. class SwitchUserSubscriber implements EventSubscriberInterface
  9. {
  10.     private Security $security;
  11.     private SwitchUserLogManager $switchUserLogManager;
  12.     public function __construct(Security $securitySwitchUserLogManager $switchUserLogManager)
  13.     {
  14.         $this->security $security;
  15.         $this->switchUserLogManager $switchUserLogManager;
  16.     }
  17.     public function onSwitchUser(SwitchUserEvent $event): void
  18.     {
  19.         $this->switchUserLogManager->create($this->security->getUser(), $event->getTargetUser());
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             // constant for security.switch_user
  25.             SecurityEvents::SWITCH_USER => 'onSwitchUser',
  26.         ];
  27.     }
  28. }