vendor/crosiersource/crosierlib-base/src/EventSubscriber/KernelSubscriber.php line 58

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibBaseBundle\EventSubscriber;
  3. use CrosierSource\CrosierLibBaseBundle\APIClient\Security\SecurityAPIClient;
  4. use Psr\Log\LoggerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. /**
  9.  * Class KernelSubscriber.
  10.  *
  11.  * Realiza em todos os request de um CrosierApp a verificação de que o mesmo ainda permanece logado no CrosierCore.
  12.  *
  13.  *
  14.  * @package CrosierSource\CrosierLibBaseBundle\EventSubscriber
  15.  * @author Carlos Eduardo Pauluk
  16.  */
  17. class KernelSubscriber implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var LoggerInterface
  21.      */
  22.     private $logger;
  23.     /**
  24.      * @var SecurityAPIClient
  25.      */
  26.     private $securityAPIClient;
  27.     public function __construct(LoggerInterface $loggerSecurityAPIClient $securityAPIClient)
  28.     {
  29.         $this->logger $logger;
  30.         $this->securityAPIClient $securityAPIClient;
  31.     }
  32.     /**
  33.      *
  34.      * @return array The event names to listen to
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             KernelEvents::REQUEST => [
  40.                 ['onKernelRequest'0],
  41.             ]
  42.         ];
  43.     }
  44.     /**
  45.      * Executa a verificação junto a api do CrosierCore se o app ainda está logado.
  46.      *
  47.      * @param RequestEvent $event
  48.      * @throws \GuzzleHttp\Exception\GuzzleException
  49.      */
  50.     public function onKernelRequest(RequestEvent $event)
  51.     {
  52. //        // Não ativa para chamadas a APIs
  53. //        if (strpos($event->getRequest()->getPathInfo(), '/api/') !== 0 &&
  54. //            strpos($event->getRequest()->getPathInfo(), '/login') !== 0 &&
  55. //            strpos($event->getRequest()->getPathInfo(), '/logout') !== 0) {
  56. //
  57. ////            if (isset($_SERVER['CROSIERAPP_ID']) && (isset($_SERVER['CROSIERAPP_LOGINBYCORE']) && filter_var($_SERVER['CROSIERAPP_LOGINBYCORE'], FILTER_VALIDATE_BOOLEAN) === true)) {
  58. //            $loginState = null;
  59. //            try {
  60. //                $loginState = $this->securityAPIClient->checkLoginState();
  61. //                if ($loginState && isset($loginState['hasApiToken']) && $loginState['hasApiToken']) {
  62. //                    return; // OK
  63. //                }
  64. //            } catch (\Throwable $e) {
  65. //                $this->logger->error('onKernelRequest error (loginState)');
  66. //                $this->logger->error(print_r($loginState, true));
  67. //            }
  68. //            // problema com o loginState... manda para o logout (que por sua vez mandará para o login)
  69. //            $event->setResponse(
  70. //                new RedirectResponse(
  71. //                    $_SERVER['CROSIERCORE_URL'] . '/logout'
  72. //                )
  73. //            );
  74. //
  75. //        }
  76.     }
  77. }