<?php
namespace App\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ControllerListener
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
* @var ContainerInterface
*/
private $container;
/**
* ControllerListener constructor.
*
* @param TokenStorageInterface $tokenStorage
* @param ContainerInterface $container
*/
public function __construct(TokenStorageInterface $tokenStorage, ContainerInterface $container)
{
$this->tokenStorage = $tokenStorage;
$this->container = $container;
}
public function onKernelController(FilterControllerEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
$session = $this->container->get('session');
$refreshExpiration = $session->get('refreshExpiration');
if ($refreshExpiration < time()) {
return new Response('', 401);
}
}
}