src/Session/Configurator/SessionEspiritConfigurator.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Session\Configurator;
  3.  
  4. use Pimcore\Session\SessionConfiguratorInterface;
  5. use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
  6. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpKernel\Event\KernelEvent;
  10. use Symfony\Component\HttpKernel\KernelEvents;
  11. use Symfony\Component\HttpKernel\Event\RequestEvent;
  12.  
  13. class SessionEspiritConfigurator implements EventSubscriberInterface
  14. {
  15.     public static function getSubscribedEvents(): array
  16.     {   
  17.         return [
  18.             //run after Symfony\Component\HttpKernel\EventListener\SessionListener
  19.             KernelEvents::REQUEST => ['onKernelRequest'127],
  20.         ];
  21.     }
  22.     public function onKernelRequest(RequestEvent $event): void
  23.     {  
  24.         if (!$event->isMainRequest()) {
  25.             return;
  26.         }
  27.         
  28.         if ($event->getRequest()->attributes->get('_espirit'false)) {
  29.             return;
  30.         }
  31.         $session $event->getRequest()->getSession();
  32.         
  33.         //do not register bags, if session is already started
  34.         if ($session->isStarted()) {
  35.             return;
  36.         }
  37.         $bag = new AttributeBag('_espirit');
  38.         $bag->setName('espirit');
  39.  
  40.         $session->registerBag($bag);
  41.     }
  42.     /**
  43.      * @inheritDoc
  44.      */
  45.     // public function configure(SessionInterface $session)
  46.     // {
  47.     //     $bag = new NamespacedAttributeBag('_espirit');
  48.     //     $bag->setName('espirit');
  49.  
  50.     //     $session->registerBag($bag);
  51.     // }
  52. }