Skip to content

Commit beeb4b9

Browse files
committed
[Messenger] Simplify code
1 parent 13167e8 commit beeb4b9

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Symfony/Component/Messenger/Event/SendMessageToTransportsEvent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*
2020
* The event is *only* dispatched if the message will actually
2121
* be sent to at least one transport. If the message is sent
22-
* to multiple transports, the message is dispatched only once.
23-
* This message is only dispatched the first time a message
22+
* to multiple transports, the event is dispatched only once.
23+
* This event is only dispatched the first time a message
2424
* is sent to a transport, not also if it is retried.
2525
*
2626
* @author Ryan Weaver <[email protected]>

src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,16 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
4747
// it's a received message, do not send it back
4848
$this->logger?->info('Received message {class}', $context);
4949
} else {
50-
$shouldDispatchEvent = true;
5150
$senders = $this->sendersLocator->getSenders($envelope);
5251
$senders = \is_array($senders) ? $senders : iterator_to_array($senders);
53-
foreach ($senders as $alias => $sender) {
54-
if (null !== $this->eventDispatcher && $shouldDispatchEvent) {
55-
$event = new SendMessageToTransportsEvent($envelope, $senders);
56-
$this->eventDispatcher->dispatch($event);
57-
$envelope = $event->getEnvelope();
58-
$shouldDispatchEvent = false;
59-
}
6052

53+
if (null !== $this->eventDispatcher && $senders) {
54+
$event = new SendMessageToTransportsEvent($envelope, $senders);
55+
$this->eventDispatcher->dispatch($event);
56+
$envelope = $event->getEnvelope();
57+
}
58+
59+
foreach ($senders as $alias => $sender) {
6160
$this->logger?->info('Sending message {class} with {alias} sender using {sender}', $context + ['alias' => $alias, 'sender' => $sender::class]);
6261
$envelope = $sender->send($envelope->with(new SentStamp($sender::class, \is_string($alias) ? $alias : null)));
6362
}

0 commit comments

Comments
 (0)