<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\Response;
use AcroMedia\AcroNetBundle\Service\AcroNet;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* Listener that assures the user is authenticated.
*/
class AcroNetListener
{
private $acronet;
/**
* Constructor
*
* @param AcroNet $acronet
*/
public function __construct(AcroNet $acronet)
{
$this->acronet = $acronet;
}
/**
* Event hook for any requests.
*
* @param GetResponseEvent $event
*
* @return mixed
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$this->acronet->isAuthenticated()) {
$response = new Response('You must be logged into AcroNet to proceed.');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$event->setResponse($response);
}
}
}