src/AppBundle/EventListener/AcroNetListener.php line 33

Open in your IDE?
  1. <?php
  2. namespace AppBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use AcroMedia\AcroNetBundle\Service\AcroNet;
  5. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  6. /**
  7.  * Listener that assures the user is authenticated.
  8.  */
  9. class AcroNetListener
  10. {
  11.     private $acronet;
  12.     /**
  13.      * Constructor
  14.      *
  15.      * @param AcroNet $acronet
  16.      */
  17.     public function __construct(AcroNet $acronet)
  18.     {
  19.         $this->acronet $acronet;
  20.     }
  21.     /**
  22.      * Event hook for any requests.
  23.      *
  24.      * @param GetResponseEvent $event
  25.      *
  26.      * @return mixed
  27.      */
  28.     public function onKernelRequest(GetResponseEvent $event)
  29.     {
  30.         if (!$this->acronet->isAuthenticated()) {
  31.             $response = new Response('You must be logged into AcroNet to proceed.');
  32.             $response->setStatusCode(Response::HTTP_FORBIDDEN);
  33.             $event->setResponse($response);
  34.         }
  35.     }
  36. }