File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,40 @@ You can add multiple ``#[AsEventListener()]`` attributes to configure different
191
191
}
192
192
}
193
193
194
+ :class: `Symfony\\ Component\\ EventDispatcher\\ Attribute\\ AsEventListener `
195
+ can also be applied to methods directly::
196
+
197
+ namespace App\EventListener;
198
+
199
+ use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
200
+
201
+ final class MyMultiListener
202
+ {
203
+ #[AsEventListener()]
204
+ public function onCustomEvent(CustomEvent $event): void
205
+ {
206
+ // ...
207
+ }
208
+
209
+ #[AsEventListener(event: 'foo', priority: 42)]
210
+ public function onFoo(): void
211
+ {
212
+ // ...
213
+ }
214
+
215
+ #[AsEventListener(event: 'bar')]
216
+ public function onBarEvent(): void
217
+ {
218
+ // ...
219
+ }
220
+ }
221
+
222
+ .. note ::
223
+
224
+ You can notice that the attribute doesn't require its ``event ``
225
+ parameter to be set if the method already type-hints the
226
+ expected event.
227
+
194
228
.. _events-subscriber :
195
229
196
230
Creating an Event Subscriber
You can’t perform that action at this time.
0 commit comments