Skip to content

Commit

Permalink
bug #34677 [EventDispatcher] Better error reporting when arguments to…
Browse files Browse the repository at this point in the history
… dispatch() are swapped (rimas-kudelis)

This PR was squashed before being merged into the 4.3 branch.

Discussion
----------

[EventDispatcher] Better error reporting when arguments to dispatch() are swapped

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34676
| License       | MIT

Incorrect error is currently being reported when the second argument is an instance of `Symfony\Contracts\EventDispatcher\Event`.

Commits
-------

54aac56 [EventDispatcher] Better error reporting when arguments to dispatch() are swapped
  • Loading branch information
nicolas-grekas committed Nov 28, 2019
2 parents 81ba73c + 54aac56 commit 28c3b3e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/EventDispatcher/EventDispatcher.php
Expand Up @@ -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();
Expand Down
Expand Up @@ -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();
Expand Down

0 comments on commit 28c3b3e

Please sign in to comment.