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

Skip to content

Commit 12b1219

Browse files
Update UPGRADE guide of 4.3 for EventDispatcher
1 parent f51f7e7 commit 12b1219

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

UPGRADE-4.3.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ EventDispatcher
5555
---------------
5656

5757
* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
58+
59+
You have to swap arguments when calling `dispatch()`:
60+
61+
Before:
62+
```php
63+
$this->eventDispatcher->dispatch(Events::My_EVENT, $event);
64+
```
65+
66+
After:
67+
```php
68+
$this->eventDispatcher->dispatch($event, Events::My_EVENT);
69+
```
70+
71+
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:
72+
73+
Before:
74+
```php
75+
public function __construct(EventDispatcherInterface $eventDispatcher) {
76+
$this->eventDispatcher = $eventDispatcher;
77+
}
78+
```
79+
80+
After:
81+
```php
82+
public function __construct(EventDispatcherInterface $eventDispatcher) {
83+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
84+
}
85+
```
86+
5887
* The `Event` class has been deprecated, use `Symfony\Contracts\EventDispatcher\Event` instead
5988

6089
Filesystem

0 commit comments

Comments
 (0)