src/EventSubscriber/KernelRequestListener.php line 44
<?php
namespace App\EventSubscriber;
use App\Controller\ReturnImpostazioniServiceController;
use App\Controller\ServiziController;
use Monolog\Logger;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Bundle\SecurityBundle\Security;
/**
* Class KernelRequestListener
* @package App\EventSubscriber
*/
class KernelRequestListener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
private ServiziController $servizi;
private ReturnImpostazioniServiceController $imp;
private $tokenStorage;
private $logger;
private Security $security;
public function __construct(ServiziController $servizi, TokenStorageInterface $tokenStorage, Logger $logger, ReturnImpostazioniServiceController $imp, Security $security)
{
$this->servizi = $servizi;
$this->security = $security;
$this->logger = $logger;
$this->tokenStorage = $tokenStorage;
$this->imp = $imp;
}
/**
* @param FinishRequestEvent $event
*/
public function onKernelFinishRequest(FinishRequestEvent $event)
{
if (!$event->isMainRequest()) {
return;
}
/*
if (!$token = $this->tokenStorage->getToken()) {
return ;
}
if (!$token->isAuthenticated()) {
return ;
}
if (!$user = $token->getUser()) {
return ;
}*/
if($this->imp->ritornaImpostazioneDaNome('AbilitaRegistroAttivitaUtenti') == '1') {
$user = $this->security->getUser();
if ($user) {
if (in_array('ROLE_ADMIN', $this->security->getUser()->getRoles())) {
$this->servizi->ScriviRegistroAttivitaUtente($this->security->getUser(), 'Navigazione', 'Apertura pagina: ' . $event->getRequest()->getUri());
}
}
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * ['eventName' => 'methodName']
* * ['eventName' => ['methodName', $priority]]
* * ['eventName' => [['methodName1', $priority], ['methodName2']]]
*
* The code must not depend on runtime state as it will only be called at compile time.
* All logic depending on runtime state must be put into the individual methods handling the events.
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return array(
// must be registered before the default Locale listener
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 17)),
);
}
}