$sender = null;
if ($envelope->
all(ReceivedStamp::
class)) { // it's a received message, do not send it back
$this->logger?->
info('Received message {class}',
$context);
} else { $shouldDispatchEvent = true;
$senders =
$this->sendersLocator->
getSenders($envelope);
$senders = \
is_array($senders) ?
$senders :
iterator_to_array($senders);
foreach ($senders as $alias =>
$sender) { if (null !==
$this->eventDispatcher &&
$shouldDispatchEvent) { $event =
new SendMessageToTransportsEvent($envelope,
$senders);
$this->eventDispatcher->
dispatch($event);
$envelope =
$event->
getEnvelope();
$shouldDispatchEvent = false;
} $this->logger?->
info('Sending message {class} with {alias} sender using {sender}',
$context +
['alias' =>
$alias, 'sender' =>
$sender::
class]);
$envelope =
$sender->
send($envelope->
with(new SentStamp($sender::
class, \
is_string($alias) ?
$alias : null
)));
} if (!
$this->allowNoSenders && !
$sender) { throw new NoSenderForMessageException(sprintf('No sender for message "%s".',
$context['class'
]));
}