Monday, August 25, 2014

Listen switch_user Event in #Symfony


#config.yml 
services: 
  myproject.security_switch_user: 
    class: MyApp\AppBundle\Listener\SecuritySwitchUserListener 
    tags: 
      - { 
         name: kernel.event_listener, 
         event: security.switch_user, 
         method: onSecuritySwitchUser }
<?php
// src/MyApp/AppBundle/Listener/SecuritySwitchUserListener.php
namespace MyApp\AppBundle\Listener;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
class SecuritySwitchUserListener
{
public function onSecuritySwitchUser(SwitchUserEvent $event)
{
$newUser = $event->getTargetUser();
} }

No comments: