<?php
namespace App\Session\Configurator;
use Pimcore\Session\SessionConfiguratorInterface;
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class SessionEspiritConfigurator implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
//run after Symfony\Component\HttpKernel\EventListener\SessionListener
KernelEvents::REQUEST => ['onKernelRequest', 127],
];
}
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
if ($event->getRequest()->attributes->get('_espirit', false)) {
return;
}
$session = $event->getRequest()->getSession();
//do not register bags, if session is already started
if ($session->isStarted()) {
return;
}
$bag = new AttributeBag('_espirit');
$bag->setName('espirit');
$session->registerBag($bag);
}
/**
* @inheritDoc
*/
// public function configure(SessionInterface $session)
// {
// $bag = new NamespacedAttributeBag('_espirit');
// $bag->setName('espirit');
// $session->registerBag($bag);
// }
}