vendor/pimcore/pimcore/bundles/CoreBundle/DependencyInjection/Compiler/SessionConfiguratorPass.php line 65

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\CoreBundle\DependencyInjection\Compiler;
  15. use Pimcore\Session\SessionConfigurator;
  16. use Pimcore\Session\SessionConfiguratorInterface;
  17. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  18. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\DependencyInjection\Reference;
  21. /**
  22.  * @TODO remove in Pimcore 11
  23.  *
  24.  * @internal
  25.  */
  26. final class SessionConfiguratorPass implements CompilerPassInterface
  27. {
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function process(ContainerBuilder $container)
  32.     {
  33.         // @phpstan-ignore-next-line
  34.         if (!$container->has('session')) {
  35.             return;
  36.         }
  37.         // @phpstan-ignore-next-line
  38.         if (!$container->has(SessionConfigurator::class)) {
  39.             return;
  40.         }
  41.         // configure the core session through our configurator service (mainly to register custom attribute bags)
  42.         $session $container->findDefinition('session');
  43.         // just to make sure nobody else (symfony core, other bundle) sets a configurator and we overwrite it here
  44.         if ($session->getConfigurator()) {
  45.             throw new InvalidConfigurationException('The session service already defines a configurator.');
  46.         }
  47.         $session->setConfigurator([new Reference(SessionConfigurator::class), 'configure']);
  48.         $this->addTaggedConfigurators($container);
  49.     }
  50.     /**
  51.      * Finds all configurators tagged as pimcore.session.configurator and adds them to the configurator collection
  52.      *
  53.      * @param ContainerBuilder $container
  54.      */
  55.     protected function addTaggedConfigurators(ContainerBuilder $container)
  56.     {
  57.         $configurator $container->getDefinition(SessionConfigurator::class);
  58.         $taggedServices $container->findTaggedServiceIds('pimcore.session.configurator');
  59.         foreach ($taggedServices as $id => $tags) {
  60.             if (($tags[0]['type'] ?? null) !== 'internal') {
  61.                 trigger_deprecation('pimcore/pimcore''10.5',
  62.                     sprintf('Implementation of %s is deprecated since version 10.5 and will be removed in Pimcore 11.' .
  63.                         'Implement the Event Listener instead.'SessionConfiguratorInterface::class));
  64.             }
  65.             $configurator->addMethodCall('addConfigurator', [new Reference($id)]);
  66.         }
  67.     }
  68. }