-
-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.