-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Select alternatives on missing receiver arg or typo #27230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. < 10000 a class="Link--inTextBlock" data-turbo="false" href="" aria-label="Please reload this page">Please reload this page.
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,8 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser | |
private function registerReceivers(ContainerBuilder $container) | ||
{ | ||
$receiverMapping = array(); | ||
$taggedReceivers = $container->findTaggedServiceIds($this->receiverTag); | ||
|
||
foreach ($taggedReceivers as $id => $tags) { | ||
foreach ($container->findTaggedServiceIds($this->receiverTag) as $id => $tags) { | ||
$receiverClass = $container->findDefinition($id)->getClass(); | ||
if (!is_subclass_of($receiverClass, ReceiverInterface::class)) { | ||
throw new RuntimeException(sprintf('Invalid receiver "%s": class "%s" must implement interface "%s".', $id, $receiverClass, ReceiverInterface::class)); | ||
|
@@ -183,8 +182,12 @@ private function registerReceivers(ContainerBuilder $container) | |
} | ||
} | ||
|
||
if (1 === \count($taggedReceivers) && $container->hasDefinition('console.command.messenger_consume_messages')) { | ||
$container->getDefinition('console.command.messenger_consume_messages')->replaceArgument(3, (string) current($receiverMapping)); | ||
if ($container->hasDefinition('console.command.messenger_consume_messages')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relates to above, I think we should only have the default defined if there is just one like in removed lines (but still inject all names independently for interactivity) |
||
$receiverNames = array(); | ||
foreach ($receiverMapping as $name => $reference) { | ||
$receiverNames[(string) $reference] = $name; | ||
} | ||
$container->getDefinition('console.command.messenger_consume_messages')->replaceArgument(3, array_values($receiverNames)); | ||
} | ||
|
||
$container->getDefinition('messenger.receiver_locator')->replaceArgument(0, $receiverMapping); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already somewhere else? Can't we share instead of copy? Maybe at least reference the other occurrences if it has been pasted so we know when maintaining it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from debug command of the Form component, but still there is other places where similar procedure has been used, probably a
trait
could be created for such cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don"t have a central place for such logic for 2 reasons: it's small enough and we don't want to create a "util" component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabpot a good practice can be to add a comment that refers to the place it was copy/pasted from.