src/ApiBundle/EventListener/AuthenticateListener.php line 23

Open in your IDE?
  1. <?php
  2. namespace ApiBundle\EventListener;
  3. use ApiBundle\Security\Firewall\XAuthTokenAuthenticationListener;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\Security\Core\Event\AuthenticationEvent;
  6. use AppBundle\Component\Track\UserOnlineTrack;
  7. class AuthenticateListener
  8. {
  9.     private $container;
  10.     private $userOnlineTrack;
  11.     public function __construct(ContainerInterface $containerUserOnlineTrack $userOnlineTrack)
  12.     {
  13.         $this->container $container;
  14.         $this->userOnlineTrack $userOnlineTrack;
  15.     }
  16.     public function onAuthenticate(AuthenticationEvent $event)
  17.     {
  18.         $request $this->container->get('request_stack')->getMainRequest();
  19.         $authToken $request->headers->get(XAuthTokenAuthenticationListener::TOKEN_HEADER);
  20.         if (!empty($authToken)) {
  21.             $this->userOnlineTrack->track($request->headers->get(XAuthTokenAuthenticationListener::TOKEN_HEADER));
  22.         }
  23.     }
  24. }