Skip to content

Commit e3c88c4

Browse files
Rimas Kudelisnicolas-grekas
authored andcommitted
[EventDispatcher] Better error reporting when arguments to dispatch() are swapped
1 parent 0df002f commit e3c88c4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

EventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function dispatch($event/*, string $eventName = null*/)
5454

5555
if (\is_object($event)) {
5656
$eventName = $eventName ?? \get_class($event);
57-
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) {
57+
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) {
5858
@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);
5959
$swap = $event;
6060
$event = $eventName ?? new Event();

LegacyEventDispatcherProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function dispatch($event/*, string $eventName = null*/)
5959

6060
if (\is_object($event)) {
6161
$eventName = $eventName ?? \get_class($event);
62-
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) {
62+
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) {
6363
@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);
6464
$swap = $event;
6565
$event = $eventName ?? new Event();

0 commit comments

Comments
 (0)