2
2
3
3
namespace Symfony \UX \LiveComponent \EventListener ;
4
4
5
+ use Psr \Container \ContainerInterface ;
5
6
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
7
+ use Symfony \Contracts \Service \ServiceSubscriberInterface ;
6
8
use Symfony \UX \LiveComponent \Twig \LiveComponentRuntime ;
7
9
use Symfony \UX \TwigComponent \ComponentAttributes ;
8
10
use Symfony \UX \TwigComponent \EventListener \PreRenderEvent ;
9
11
10
12
/**
11
13
* @author Kevin Bond <[email protected] >
12
14
*/
13
- final class AddLiveAttributesSubscriber implements EventSubscriberInterface
15
+ final class AddLiveAttributesSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
14
16
{
15
- public function __construct (private LiveComponentRuntime $ runtime )
17
+ public function __construct (private ContainerInterface $ container )
16
18
{
17
- // todo make lazy?
18
19
}
19
20
20
21
public function onPreRender (PreRenderEvent $ event ): void
@@ -24,7 +25,10 @@ public function onPreRender(PreRenderEvent $event): void
24
25
return ;
25
26
}
26
27
27
- $ attributes = $ this ->runtime ->getLiveAttributes ($ event ->component , $ event ->config );
28
+ /** @var ComponentAttributes $attributes */
29
+ $ attributes = $ this ->container ->get (LiveComponentRuntime::class)
30
+ ->getLiveAttributes ($ event ->component , $ event ->config )
31
+ ;
28
32
29
33
if (isset ($ event ->context ['attributes ' ]) && $ event ->context ['attributes ' ] instanceof ComponentAttributes) {
30
34
// merge with existing attributes if available
@@ -38,4 +42,11 @@ public static function getSubscribedEvents(): array
38
42
{
39
43
return [PreRenderEvent::class => 'onPreRender ' ];
40
44
}
45
+
46
+ public static function getSubscribedServices (): array
47
+ {
48
+ return [
49
+ LiveComponentRuntime::class,
50
+ ];
51
+ }
41
52
}
0 commit comments