Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] Allow to typehint multiple buses#27054
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
chalasr left a comment
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.
mainly wording suggestions
| * | ||
| * @author Samuel Roze <samuel.roze@gmail.com> | ||
| */ | ||
| abstractclass DecoratedMessageBusimplements MessageBusInterface |
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.
If concrete children are decorators then this is a base decorator, isn't it? Also core abstract classes are prefixed byAbstract so,AbstractMessageBusDecorator?
| /** | ||
| * A decorated message bus. | ||
| * | ||
| * Use this abstract class to created your message bus decorator to specialise your |
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.
typoto create
| * A decorated message bus. | ||
| * | ||
| * Use this abstract class to created your message bus decorator to specialise your | ||
| * bus instances and type-hint them. |
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.
I suggesttype-hint against them, dependents type-hint one of their dependencies against the type they need
| $tagAttributes =array('name' =>$name); | ||
| if (isset($bus['decorator_class'])) { | ||
| $tagAttributes['decorator_class'] =$bus['decorator_class']; |
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.
should it fail if the class does not implementMessageBusInterface at least? Perhaps give a complete hint about what is needed for using this option
| } | ||
| } | ||
| finalclass MyTypeHintedBusextends DecoratedMessageBus |
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.
TypeHinted is misleading here :) a class is a type, method arguments are type-hinted
ro0NL commentedApr 26, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
you'll get the default bus AFAIK...
What if the same decorated class is used multiple times across buses? isn't this just like saying |
sroze commentedApr 27, 2018
Well, you know what is going to happen: the auto-wiring won't be happy :)
Ish. It still means you'd have to create the |
ro0NL commentedApr 27, 2018
Or just a trait maybe =/ i would indeed avoid the FWB config. |
sroze commentedApr 27, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It works well with the following configuration 👍 services:'App\Bus\CommandBus':decorates:"messenger.bus.commands" |
99669ba to2b601adComparesroze commentedApr 27, 2018
To be completed by a lovely documentation :) |
kbond commentedApr 27, 2018
In development, with the following configuration: services:'App\Bus\CommandBus':decorates:"messenger.bus.commands" The decorated bus is an instance of |
sroze commentedApr 27, 2018
@kbond you need to typehint ither |
kbond commentedApr 27, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@sroze I type-hinted my own bus which extends from It is the correct bus it just doesn't show any activity in the profiler. |
sroze commentedApr 27, 2018
I'm sorry but I don't understand the problem... "it works well on my machine" 😅 Can you give me the exact error you face and the classes & configuration you have? :) |
kbond commentedApr 27, 2018
There is no error. messenger config: framework:messenger:default_bus:eventbuses:command:default_middlewares:falsemiddlewares: -logging -Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware -call_message_handlerquery:default_middlewares:falsemiddlewares: -logging -call_message_handlerevent:middleware: -tolerate_no_handler service config: services:App\Messenger\CommandBus:decorates:messenger.bus.command my command bus class: namespaceApp\Messenger;useSymfony\Component\Messenger\AbstractMessageBusDecorator;finalclass CommandBusextends AbstractMessageBusDecorator{} controller injecting command bus: publicfunctionmyAction(CommandBus$commandBus){dump($commandBus);// ...} Screenshot of dumped Notice the decorated bus is just |
kbond commentedApr 27, 2018
sroze commentedApr 27, 2018
Oh, excellent. Thank you for checking that. That's what will be in the documentation then :) |
sroze commentedApr 28, 2018
Status: Ready |
ro0NL left a comment
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.
not sure core needs it.. (i'd write this out anyway :)) but 👍 for the intend allthough i'd use a trait to avoid inheritance and own the private decorated bus in my own class.
weaverryan left a comment
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.
Hmm, it seems like a pretty small feature in its final form. So, I think it's ok.@sroze can you open a Docs PR before this gets merged with a quick dump of the final "docs" needed to make this work? I'm not 100% clear which service configuration was finally the correct one from the comments.
sroze commentedMay 3, 2018
nicolas-grekas commentedMay 4, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm very skeptical about this PR and the related § insymfony/symfony-docs#9727. |
sroze commentedMay 4, 2018 via email
As you know, I agree with you... What if we change the documentation toshow an example with creating the interface? For 4.1, this is very likelyto be the only option we can have in IMHO :) …On Fri, 4 May 2018 at 04:02, Nicolas Grekas ***@***.***> wrote: I'm very skeptical about this PR and the related § insymfony/symfony-docs#9727 <symfony/symfony-docs#9727>. This encourages type-hinting against a concrete implementation and totally breaks SOLID, isn't it? I acknowledge there is a DX issue and that this proposal tries to solve it. Coincidentally, I was talking about the exact same issue with@weaverryan <https://github.com/weaverryan> today, tell him about a solution we might want to push forward in 4.2. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#27054 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAxHEXK2IaTUiHVjw76nM1eR29U5okjfks5tu8TJgaJpZM4TkFYV> . |
nicolas-grekas commentedMay 4, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No need for any dedicated interfaces, using bindings solves the issue: |
sroze commentedMay 4, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Outch. Not sure how I feel about that one. I'll give a try. |
nicolas-grekas commentedMay 5, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
As explained, I'm:-1: as this would put users in a dead end. We should tell about using bindings instead, and seek for a better experience in 4.2 that doesn't break SOLID. |
sroze commentedMay 6, 2018
Closing, as I'll update the documentation to recommend the binding, that makes sense actually. |


When defining multiple buses, it becomes impossible to type-hint the
MessageBusInterface. This PR adds the ability to wrap the bus within a decorator that you will be able to typehint.As a developer, you will create your classes:
Configure your bus to use it:
You can now typehint your
CommandBus🥁 💃 ⭐️