vendor/symfony/mercure-bundle/src/MercureBundle.php line 26

  1. <?php
  2. /*
  3.  * This file is part of the Mercure Component project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Symfony\Bundle\MercureBundle;
  12. use Symfony\Bundle\MercureBundle\DependencyInjection\CompilerPass\StimulusHelperPass;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\HttpKernel\Bundle\Bundle;
  17. use Symfony\Component\Mercure\Authorization;
  18. /**
  19.  * @author Kévin Dunglas <dunglas@gmail.com>
  20.  */
  21. final class MercureBundle extends Bundle
  22. {
  23.     public function build(ContainerBuilder $container): void
  24.     {
  25.         parent::build($container);
  26.         $container->addCompilerPass(new StimulusHelperPass());
  27.         $container->addCompilerPass(new class() implements CompilerPassInterface {
  28.             public function process(ContainerBuilder $container): void
  29.             {
  30.                 if (!$container->hasDefinition(Authorization::class)) {
  31.                     return;
  32.                 }
  33.                 $definition $container->getDefinition(Authorization::class);
  34.                 if (
  35.                     null === $definition->getArgument(1)
  36.                     && $container->hasParameter('session.storage.options')
  37.                 ) {
  38.                     $definition->setArgument(
  39.                         1,
  40.                         $container->getParameter('session.storage.options')['cookie_lifetime'] ?? null
  41.                     );
  42.                 }
  43.             }
  44.         }, PassConfig::TYPE_BEFORE_REMOVING);
  45.     }
  46. }