vendor/symfony/ux-turbo/src/TurboBundle.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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. 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 <kevin@dunglas.fr>
  18. */
  19. final class TurboBundle extends Bundle
  20. {
  21. public const STREAM_FORMAT = 'turbo_stream';
  22. public const STREAM_MEDIA_TYPE = 'text/vnd.turbo-stream.html';
  23. public function boot(): void
  24. {
  25. (new Request())->setFormat(self::STREAM_FORMAT, self::STREAM_MEDIA_TYPE);
  26. }
  27. public function build(ContainerBuilder $container): void
  28. {
  29. parent::build($container);
  30. $container->addCompilerPass(new class() implements CompilerPassInterface {
  31. public function process(ContainerBuilder $container): void
  32. {
  33. if (!$container->hasDefinition('turbo.broadcaster.imux')) {
  34. return;
  35. }
  36. if (!$container->getDefinition('turbo.broadcaster.imux')->getArgument(0)->getValues()) {
  37. $container->removeDefinition('turbo.doctrine.event_listener');
  38. }
  39. }
  40. }, PassConfig::TYPE_BEFORE_REMOVING);
  41. }
  42. public function getPath(): string
  43. {
  44. return \dirname(__DIR__);
  45. }
  46. }