<?php
namespace App\EventSubscriber;
use DateInterval;
use DateTime;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ParrainSubscriber implements EventSubscriberInterface
{
private $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();
if (is_array($controller)) {
$controller = $controller[0];
}
$token = $event->getRequest()->get('token');
if($token != null){
$dateExpiration = new DateTime();
$dateExpiration->add(new DateInterval('PT1H'));
$this->session->set('parrain', $token);
$this->session->set('dateExpirationParrain', $dateExpiration->format("Y-m-d-H-i-s"));
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}