vendor/pimcore/pimcore/bundles/AdminBundle/EventListener/AdminSessionBagListener.php line 48

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\AdminBundle\EventListener;
  15. use Pimcore\Config;
  16. use Pimcore\Session\Attribute\LockableAttributeBag;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  19. use Symfony\Component\HttpKernel\Event\RequestEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. /**
  22.  * @internal
  23.  */
  24. class AdminSessionBagListener implements EventSubscriberInterface
  25. {
  26.     public function __construct(protected Config $config)
  27.     {
  28.     }
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             //run after Symfony\Component\HttpKernel\EventListener\SessionListener
  36.             KernelEvents::REQUEST => ['onKernelRequest'127],
  37.         ];
  38.     }
  39.     /**
  40.      * @param RequestEvent $event
  41.      */
  42.     public function onKernelRequest(RequestEvent $event)
  43.     {
  44.         if (!$event->isMainRequest()) {
  45.             return;
  46.         }
  47.         $session $event->getRequest()->getSession();
  48.         //do not register bags, if session is already started
  49.         if ($session->isStarted()) {
  50.             return;
  51.         }
  52.         $this->configure($session);
  53.     }
  54.     /**
  55.      * @param SessionInterface $session
  56.      *
  57.      */
  58.     public function configure(SessionInterface $session)
  59.     {
  60.         foreach ($this->config['admin']['session']['attribute_bags'] as $name => $config) {
  61.             $bag = new LockableAttributeBag($config['storage_key']);
  62.             $bag->setName($name);
  63.             $session->registerBag($bag);
  64.         }
  65.     }
  66. }