Update UPGRADE guide of 4.3 for EventDispatcher

This commit is contained in:
Alexis Lefebvre 2019-08-11 17:12:03 +02:00
parent f51f7e7b74
commit 8b9b39d872
No known key found for this signature in database
GPG Key ID: 3DCE39C7795C652A
1 changed files with 30 additions and 1 deletions

View File

@ -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