From 54aac56ab86ec4471de0b6624c101cd42a12967d Mon Sep 17 00:00:00 2001 From: Rimas Kudelis Date: Thu, 28 Nov 2019 12:42:53 +0200 Subject: [PATCH] [EventDispatcher] Better error reporting when arguments to dispatch() are swapped --- src/Symfony/Component/EventDispatcher/EventDispatcher.php | 2 +- .../Component/EventDispatcher/LegacyEventDispatcherProxy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index ebfd1ec6d5e7d..f7c66309827a4 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -54,7 +54,7 @@ public function dispatch($event/*, string $eventName = null*/) if (\is_object($event)) { $eventName = $eventName ?? \get_class($event); - } elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) { + } elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) { @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.', EventDispatcherInterface::class), E_USER_DEPRECATED); $swap = $event; $event = $eventName ?? new Event(); diff --git a/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php index be0d381a29be6..003de2efddafd 100644 --- a/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php +++ b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php @@ -59,7 +59,7 @@ public function dispatch($event/*, string $eventName = null*/) if (\is_object($event)) { $eventName = $eventName ?? \get_class($event); - } elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) { + } elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) { @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.', ContractsEventDispatcherInterface::class), E_USER_DEPRECATED); $swap = $event; $event = $eventName ?? new Event();