src/EventSubscriber/KernelRequestListener.php line 43

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Controller\ReturnImpostazioniServiceController;
  4. use App\Controller\ServiziController;
  5. use Monolog\Logger;
  6. use Symfony\Bundle\FrameworkBundle\Routing\Router;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  10. use Symfony\Component\HttpKernel\Event\RequestEvent;
  11. use Symfony\Component\HttpKernel\KernelEvents;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Bundle\SecurityBundle\Security;
  14. /**
  15.  * Class KernelRequestListener
  16.  * @package App\EventSubscriber
  17.  */
  18. class KernelRequestListener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
  19. {
  20.     private ServiziController $servizi;
  21.     private ReturnImpostazioniServiceController $imp;
  22.     private $tokenStorage;
  23.     private $logger;
  24.     private Security $security;
  25.     public function __construct(ServiziController $serviziTokenStorageInterface $tokenStorageLogger $loggerReturnImpostazioniServiceController  $impSecurity $security)
  26.     {
  27.         $this->servizi $servizi;
  28.         $this->security $security;
  29.         $this->logger $logger;
  30.         $this->tokenStorage $tokenStorage;
  31.         $this->imp $imp;
  32.     }
  33.     /**
  34.      * @param FinishRequestEvent $event
  35.      */
  36.     public function onKernelFinishRequest(FinishRequestEvent $event)
  37.     {
  38.         if (!$event->isMainRequest()) {
  39.             return;
  40.         }
  41.         /*
  42.         if (!$token = $this->tokenStorage->getToken()) {
  43.             return ;
  44.         }
  45.         if (!$token->isAuthenticated()) {
  46.             return ;
  47.         }
  48.         if (!$user = $token->getUser()) {
  49.             return ;
  50.         }*/
  51.         if($this->imp->ritornaImpostazioneDaNome('AbilitaRegistroAttivitaUtenti') == '1') {
  52.             $user $this->security->getUser();
  53.             if ($user) {
  54.                 if (in_array('ROLE_ADMIN'$this->security->getUser()->getRoles())) {
  55.                     $this->servizi->ScriviRegistroAttivitaUtente($this->security->getUser(), 'Navigazione''Apertura pagina: ' $event->getRequest()->getUri());
  56.                 }
  57.             }
  58.         }
  59.     }
  60.     /**
  61.      * Returns an array of event names this subscriber wants to listen to.
  62.      *
  63.      * The array keys are event names and the value can be:
  64.      *
  65.      *  * The method name to call (priority defaults to 0)
  66.      *  * An array composed of the method name to call and the priority
  67.      *  * An array of arrays composed of the method names to call and respective
  68.      *    priorities, or 0 if unset
  69.      *
  70.      * For instance:
  71.      *
  72.      *  * ['eventName' => 'methodName']
  73.      *  * ['eventName' => ['methodName', $priority]]
  74.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  75.      *
  76.      * The code must not depend on runtime state as it will only be called at compile time.
  77.      * All logic depending on runtime state must be put into the individual methods handling the events.
  78.      *
  79.      * @return array The event names to listen to
  80.      */
  81.     public static function getSubscribedEvents()
  82.     {
  83.         return array(
  84.             // must be registered before the default Locale listener
  85.             KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest'17)),
  86.         );
  87.     }
  88. }