Skip to content

Commit f618b02

Browse files
Add integration with symfony/ux-turbo (#44)
1 parent 5b594f7 commit f618b02

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Add `mercure.publisher` tag on publisher services
8+
* Add integration with `symfony/ux-turbo`
89

910
0.2.6
1011
-----

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018 Kévin Dunglas
1+
Copyright (c) 2021 Kévin Dunglas
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"extra": {
3333
"branch-alias": {
34-
"dev-main": "0.3.x-dev"
34+
"dev-main": "0.2.x-dev"
3535
}
3636
},
3737
"config": {

src/DependencyInjection/MercureExtension.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
use Symfony\Component\Mercure\Publisher;
4242
use Symfony\Component\Mercure\PublisherInterface;
4343
use Symfony\Component\Stopwatch\Stopwatch;
44+
use Symfony\UX\Turbo\Bridge\Mercure\Broadcaster;
45+
use Symfony\UX\Turbo\Bridge\Mercure\TurboStreamListenRenderer;
4446

4547
/**
4648
* @author Kévin Dunglas <[email protected]>
@@ -201,6 +203,24 @@ public function load(array $configs, ContainerBuilder $container)
201203

202204
$traceableHubs[$name] = new Reference("$hubId.traceable");
203205
}
206+
207+
if (\PHP_VERSION_ID >= 80000 && class_exists(Broadcaster::class)) {
208+
$container->register("turbo.mercure.{$name}.renderer", TurboStreamListenRenderer::class)
209+
->addArgument(new Reference($hubId))
210+
->addArgument(new Reference('webpack_encore.twig_stimulus_extension'))
211+
->addArgument(new Reference('turbo.id_accessor'))
212+
->addTag('turbo.renderer.stream_listen', ['transport' => $name]);
213+
214+
if ($defaultHubName === $name && 'default' !== $name) {
215+
$container->getDefinition("turbo.mercure.{$name}.renderer")
216+
->addTag('turbo.renderer.stream_listen', ['transport' => 'default']);
217+
}
218+
219+
$container->register("turbo.mercure.{$name}.broadcaster", Broadcaster::class)
220+
->addArgument($name)
221+
->addArgument(new Reference($hubId))
222+
->addTag('turbo.broadcaster');
223+
}
204224
}
205225

206226
if ($enableProfiler) {

0 commit comments

Comments
 (0)