@@ -32,6 +32,8 @@ class RegisterListenersPass implements CompilerPassInterface
32
32
33
33
private $ hotPathEvents = [];
34
34
private $ hotPathTagName ;
35
+ private $ noPreloadEvents = [];
36
+ private $ noPreloadTagName ;
35
37
36
38
public function __construct (string $ dispatcherService = 'event_dispatcher ' , string $ listenerTag = 'kernel.event_listener ' , string $ subscriberTag = 'kernel.event_subscriber ' , string $ eventAliasesParameter = 'event_dispatcher.event_aliases ' )
37
39
{
@@ -41,14 +43,28 @@ public function __construct(string $dispatcherService = 'event_dispatcher', stri
41
43
$ this ->eventAliasesParameter = $ eventAliasesParameter ;
42
44
}
43
45
44
- public function setHotPathEvents (array $ hotPathEvents , $ tagName = 'container.hot_path ' )
46
+ /**
47
+ * @return $this
48
+ */
49
+ public function setHotPathEvents (array $ hotPathEvents , string $ tagName = 'container.hot_path ' )
45
50
{
46
51
$ this ->hotPathEvents = array_flip ($ hotPathEvents );
47
52
$ this ->hotPathTagName = $ tagName ;
48
53
49
54
return $ this ;
50
55
}
51
56
57
+ /**
58
+ * @return $this
59
+ */
60
+ public function setNoPreloadEvents (array $ noPreloadEvents , string $ tagName = 'container.no_preload ' ): self
61
+ {
62
+ $ this ->noPreloadEvents = array_flip ($ noPreloadEvents );
63
+ $ this ->noPreloadTagName = $ tagName ;
64
+
65
+ return $ this ;
66
+ }
67
+
52
68
public function process (ContainerBuilder $ container )
53
69
{
54
70
if (!$ container ->hasDefinition ($ this ->dispatcherService ) && !$ container ->hasAlias ($ this ->dispatcherService )) {
@@ -64,6 +80,8 @@ public function process(ContainerBuilder $container)
64
80
$ globalDispatcherDefinition = $ container ->findDefinition ($ this ->dispatcherService );
65
81
66
82
foreach ($ container ->findTaggedServiceIds ($ this ->listenerTag , true ) as $ id => $ events ) {
83
+ $ noPreload = 0 ;
84
+
67
85
foreach ($ events as $ event ) {
68
86
$ priority = isset ($ event ['priority ' ]) ? $ event ['priority ' ] : 0 ;
69
87
@@ -99,8 +117,14 @@ public function process(ContainerBuilder $container)
99
117
100
118
if (isset ($ this ->hotPathEvents [$ event ['event ' ]])) {
101
119
$ container ->getDefinition ($ id )->addTag ($ this ->hotPathTagName );
120
+ } elseif (isset ($ this ->noPreloadEvents [$ event ['event ' ]])) {
121
+ ++$ noPreload ;
102
122
}
103
123
}
124
+
125
+ if ($ noPreload && \count ($ events ) === $ noPreload ) {
126
+ $ container ->getDefinition ($ id )->addTag ($ this ->noPreloadTagName );
127
+ }
104
128
}
105
129
106
130
$ extractingDispatcher = new ExtractingEventDispatcher ();
@@ -132,6 +156,7 @@ public function process(ContainerBuilder $container)
132
156
$ dispatcherDefinitions = [$ globalDispatcherDefinition ];
133
157
}
134
158
159
+ $ noPreload = 0 ;
135
160
ExtractingEventDispatcher::$ aliases = $ aliases ;
136
161
ExtractingEventDispatcher::$ subscriber = $ class ;
137
162
$ extractingDispatcher ->addSubscriber ($ extractingDispatcher );
@@ -143,8 +168,13 @@ public function process(ContainerBuilder $container)
143
168
144
169
if (isset ($ this ->hotPathEvents [$ args [0 ]])) {
145
170
$ container ->getDefinition ($ id )->addTag ($ this ->hotPathTagName );
171
+ } elseif (isset ($ this ->noPreloadEvents [$ args [0 ]])) {
172
+ ++$ noPreload ;
146
173
}
147
174
}
175
+ if ($ noPreload && \count ($ extractingDispatcher ->listeners ) === $ noPreload ) {
176
+ $ container ->getDefinition ($ id )->addTag ($ this ->noPreloadTagName );
177
+ }
148
178
$ extractingDispatcher ->listeners = [];
149
179
ExtractingEventDispatcher::$ aliases = [];
150
180
}
0 commit comments