Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[4.3] Update UPGRADE guide of 4.3 for EventDispatcher #33115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion UPGRADE-4.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,36 @@ Dotenv
EventDispatcher
---------------

* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
* The signature of the `EventDispatcherInterface::dispatch()` method has been updated, consider using the new signature `dispatch($event, string $eventName = null)` instead of the old signature `dispatch($eventName, $event)` that is deprecated

You have to swap arguments when calling `dispatch()`:

Before:
```php
$this->eventDispatcher->dispatch(Events::My_EVENT, $event);
```

After:
```php
$this->eventDispatcher->dispatch($event, Events::My_EVENT);
```

If your bundle or package needs to provide compatibility with the previous way of using the dispatcher, you can use `Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy::decorate()` to ease upgrades:

Before:
```php
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}
```

After:
```php
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
}
```

* The `Event` class has been deprecated, use `Symfony\Contracts\EventDispatcher\Event` instead

Filesystem
Expand Down