From d02feaa16099dece311f1bfd0f3317530ee8fad2 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sun, 5 Oct 2025 12:47:34 +0200 Subject: [PATCH] [FrameworkBundle] Add support for union types on #[AsEventListener] --- event_dispatcher.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/event_dispatcher.rst b/event_dispatcher.rst index ffa9e67aa0d..269304f4357 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -210,6 +210,12 @@ can also be applied to methods directly:: // ... } + #[AsEventListener] + public function onMultipleCustomEvent(CustomEvent|AnotherCustomEvent $event): void + { + // ... + } + #[AsEventListener(event: 'foo', priority: 42)] public function onFoo(): void { @@ -228,6 +234,10 @@ can also be applied to methods directly:: Note that the attribute doesn't require its ``event`` parameter to be set if the method already type-hints the expected event. +.. versionadded:: 7.4 + + The support for union types in the method type-hints was introduced in Symfony 7.4. + .. _events-subscriber: Creating an Event Subscriber