vendor/symfony/ux-turbo/TurboBundle.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\UX\Turbo;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpKernel\Bundle\Bundle;
  16. /**
  17.  * @author Kévin Dunglas <[email protected]>
  18.  *
  19.  * @experimental
  20.  */
  21. final class TurboBundle extends Bundle
  22. {
  23.     public const STREAM_FORMAT 'turbo_stream';
  24.     public const STREAM_MEDIA_TYPE 'text/vnd.turbo-stream.html';
  25.     public function boot(): void
  26.     {
  27.         (new Request())->setFormat(self::STREAM_FORMATself::STREAM_MEDIA_TYPE);
  28.     }
  29.     public function build(ContainerBuilder $container): void
  30.     {
  31.         parent::build($container);
  32.         $container->addCompilerPass(new class() implements CompilerPassInterface {
  33.             public function process(ContainerBuilder $container): void
  34.             {
  35.                 if (!$container->hasDefinition('turbo.broadcaster.imux')) {
  36.                     return;
  37.                 }
  38.                 if (!$container->getDefinition('turbo.broadcaster.imux')->getArgument(0)->getValues()) {
  39.                     $container->removeDefinition('turbo.doctrine.event_listener');
  40.                 }
  41.             }
  42.         }, PassConfig::TYPE_BEFORE_REMOVING);
  43.     }
  44. }