@@ -40,8 +40,9 @@ final class TwigMercureBroadcaster implements BroadcasterInterface
40
40
{
41
41
private $ twig ;
42
42
private $ messageBus ;
43
- private $ publisher = null ;
44
- private $ expressionLanguage = null ;
43
+ private $ publisher ;
44
+ private $ expressionLanguage ;
45
+ private $ entityNamespace ;
45
46
46
47
private const OPTIONS = [
47
48
// Twig options
@@ -65,13 +66,15 @@ public function __construct(
65
66
throw new \LogicException ('The broadcast feature requires PHP 8.0 or greater, you must either upgrade to PHP 8 or disable it. ' );
66
67
}
67
68
68
- if (null === $ this -> messageBus && null === $ this -> publisher ) {
69
+ if (null === $ messageBus && null === $ publisher ) {
69
70
throw new \InvalidArgumentException ('A message bus or a publisher must be provided. ' );
70
71
}
71
72
72
- if (null === $ this ->expressionLanguage ) {
73
- $ this ->expressionLanguage = new ExpressionLanguage ();
74
- }
73
+ $ this ->twig = $ twig ;
74
+ $ this ->messageBus = $ messageBus ;
75
+ $ this ->publisher = $ publisher ;
76
+ $ this ->expressionLanguage = $ expressionLanguage ?? new ExpressionLanguage ();
77
+ $ this ->entityNamespace = $ entityNamespace ;
75
78
}
76
79
77
80
public function broadcast (object $ entity , string $ action ): void
@@ -124,7 +127,7 @@ private function normalizeOptions(object $entity, string $action, array $options
124
127
$ options ['topics ' ] = (array ) ($ options ['topics ' ] ?? $ entityClass );
125
128
if (!isset ($ options ['template ' ])) {
126
129
$ dir = $ entityClass ;
127
- if (null !== $ this ->entityNamespace && 0 ! == strpos ($ entityClass , $ this ->entityNamespace )) {
130
+ if (null !== $ this ->entityNamespace && 0 = == strpos ($ entityClass , $ this ->entityNamespace )) {
128
131
$ dir = substr ($ entityClass , strlen ($ this ->entityNamespace ));
129
132
}
130
133
0 commit comments