You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #29027 [Messenger] Add some UPGRADE entries regarding 4.2 BC breaks (ogizanagi)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Messenger] Add some UPGRADE entries regarding 4.2 BC breaks
| Q | A
| ------------- | ---
| Branch? | 4.2 <!-- see below -->
| Bug fix? | no
| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | N/A
Just highlighting most relevant changes for users and their upgrade paths.
For exhaustivity, you'll still have to read the Messenger CHANGELOG file.
Commits
-------
c9786c2 [Messenger] Add some UPGRADE entries regarding 4.2 BC breaks
* The `handle` method of the `Symfony\Component\Messenger\Middleware\ValidationMiddleware` and `Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware` middlewares now requires an `Envelope` object to be given (because they implement the `EnvelopeAwareInterface`). When using these middleware with the provided `MessageBus`, you will not have to do anything. If you use the middlewares any other way, you can use `Envelope::wrap($message)` to create an envelope for your message.
186
+
* The `MiddlewareInterface::handle()` and `SenderInterface::send()` methods must now return an `Envelope` instance.
187
+
* The return value of handlers is ignored. If you used to return a value, e.g in query bus handlers, you can either:
188
+
- make your `Query` mutable to allow setting & getting a result:
189
+
```php
190
+
// When dispatching:
191
+
$bus->dispatch($query = new Query());
192
+
$result = $query->getResult();
193
+
194
+
// In your handler:
195
+
$query->setResult($yourResult);
196
+
```
197
+
- define a callable on your `Query` to be called in your handler:
198
+
```php
199
+
// When dispatching:
200
+
$bus->dispatch(new Query([$this, 'onResult']));
201
+
202
+
// In your handler:
203
+
$query->executeCallback($yourResult);
204
+
```
205
+
206
+
* The `EnvelopeAwareInterface` was removed and the `MiddlewareInterface::handle()` method now requires an `Envelope` object
207
+
as first argument. When using built-in middleware with the provided `MessageBus`, you will not have to do anything.
208
+
If you use your own `MessageBusInterface` implementation, you must wrap the message in an `Envelope` before passing it to middleware.
209
+
If you created your own middleware, you must change the signature to always expect an `Envelope`.
210
+
* The `MiddlewareInterface::handle()` second argument (`callable $next`) has changed in favor of a `StackInterface` instance.
211
+
When using built-in middleware with the provided `MessageBus`, you will not have to do anything.
212
+
If you use your own `MessageBusInterface` implementation, you can use the `StackMiddleware` implementation.
213
+
If you created your own middleware, you must change the signature to always expect an `StackInterface` instance
214
+
and call `$stack->next()->handle($envelope, $stack)` instead of `$next` to call the next middleware:
215
+
216
+
Before:
217
+
```php
218
+
public function handle($message, callable $next): Envelope
219
+
{
220
+
// do something before
221
+
$message = $next($message);
222
+
// do something after
223
+
224
+
return $message;
225
+
}
226
+
```
227
+
228
+
After:
229
+
```php
230
+
public function handle(Envelope $envelope, StackInterface $stack): Envelope
0 commit comments