src/EventListener/RegistrationListener.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use FOS\UserBundle\Event\GetResponseUserEvent;
  4. use FOS\UserBundle\FOSUserEvents;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. class RegistrationListener implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var UrlGeneratorInterface
  12.      */
  13.     private $router;
  14.     /**
  15.      * @param UrlGeneratorInterface $router
  16.      */
  17.     public function __construct(UrlGeneratorInterface $router) {
  18.         $this->router $router;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInitialize',
  24.         ];
  25.     }
  26.     public function onRegistrationInitialize(GetResponseUserEvent $event)
  27.     {
  28.         $url $this->router->generate('fos_user_security_login');
  29.         $response = new RedirectResponse($url);
  30.         $event->setResponse($response);
  31.     }
  32. }