-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Add middleware allowing just for a single handler #28716
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
Conversation
7088a74
to
d0a42d2
Compare
d0a42d2
to
144ae61
Compare
{ | ||
$handler = $this->messageHandlerResolver->resolve($message); | ||
|
||
if ($handler instanceof ChainHandler) { |
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 feel like this is tight coupling to a specific implementation: any other handler could implement a chained behavior, isn't it?
Why do we want to restrict the possibilities here?
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, this is coupled with the FrameworkBundle
implementation. Unfortunately, I don't have any idea on how to make it better (I don't think that sharing the YAML configuration is better either). @nicolas-grekas do you have an idea? 🤔
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.
Yeah, I also don't think this is the best solution, but I couldn't think of any other way (apart from introducing such a constraint into FrameworkBundle
itself).
We want to restrict it only to one handler to prevent any issues with having two handlers handling the same command (which could happen by accident, especially if using autowiring and autoconfiguration).
$handler = $this->messageHandlerResolver->resolve($message); | ||
|
||
if ($handler instanceof ChainHandler) { | ||
throw new MoreThanOneHandlerForMessageException(sprintf('More than one handler for message "%s".', \get_class($message))); |
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.
The other "problem" (or challenge) with the current implementation is that we can't display which are the implementations. It would massively help the developer, isn't it?
I wonder if running this check at runtime for each message dispatched really makes sense. It's not runtime dependent at all (hence, not really valid as a middleware), so perhaps we should rather just make it a bus option ? |
Sounds reasonable actually. An option and the bus and the |
Note that now |
I don't think this is really possible.
It would be easy to implement as a new argument in
|
@Tobion : Sure, this comment is outdated and was referring to another era where the ChainHandler existed and everything was guessed at compilation-time. Perhaps you're right :)
Well, if you want to add this check, (I guess) you're likely to use simple objects without inheritance nor interface in your bus. This check at compilation-time based on
If it's not used, then it should have been removed? This check isn't for a particular message, but for the whole bus. (I mean you're not asking if there is an issue with a specific message but if there isn't one in the whole bus which may be mis-configured). |
Closing in favor of #29167, thanks for the PR. |
It's a quite common middleware, required for command buses.
PS. How do you manage to have autocompletion for PHPUnit classes when writing tests in Symfony since there is no PHPUnit in dependencies?