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