-
Notifications
You must be signed in to change notification settings - Fork 23
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
AutoRegister all public methods #53
AutoRegister all public methods #53
Conversation
I see there was already some discussion about this in #43. It was mentioned that if you need to handle more events, you create an abstract subscriber and then use that. I don't think this bridge should enforce this. I know SRP, sometimes there are just 2 or more events that need the same handling :) |
The reason why I primary don't like to add al public methods is that for command handlers i don't think you should ever add two commands to one handler. For events i think it should be viable to do so. The other objection I have is that i have no controle over which methods gets registered in this case all public methods. But if i look at the Symfony event listener i can do two things (as far as i know).
The current AutoRegister creates a third option and implies the use of the So we currently support method 1. to manual add tags and the 3. option for the interface MessageSubscriberInterface
{
public function getSubscribedMessages();
} class MyCommandHandler implements MessageSubscriberInterface
{
public function getSubscribedMessages()
{
return [
MyFirstCommand::class => 'handleThisOne',
MySecondCommand::class => 'handleThisTo',
];
}
public function handleThisOne(MyFirstCommand $command)
{
// Do stuff
}
public function handleThisTo(MySecondCommand $command)
{
// Do stuff
}
} With trait trait SubscribeAllPublicMethods
{
public function getSubscribedMessages()
{
// Logic to extract all public methods
}
} class MyCommandHandler implements MessageSubscriberInterface
{
use SubscribeAllPublicMethods;
public function handleThisOne(MyFirstCommand $command)
{
// Do stuff
}
public function handleThisTo(MySecondCommand $command)
{
// Do stuff
}
} |
I like your idea. But I still don't like the fact that I have to implement an interface or use a trait. Currently, Commands, Events, Handlers and Subscribers don't need to extend any SimpleBus interface. You just map everything together with DIC. What if we go with the approach from this PR, but only if the services are tagged with a special parameter? Like |
@ruudk With the AutoWire feature in mind can we add different parameters from the
|
Does Adding Additional Attributes on Tags also work with auto wire? |
Yes, I will make a POC :) |
I was thinking to allow 3 strategies
|
@cmodijk I like Can you please create v3.0.1 for MessageBus so that my tests will work? :) |
A complete different note; We know have two classes to wire commands (events) to handlers (subscribers) But the
|
I see that my other comment was never posted. Do we create a v3.0.1 version or a v3.1.0 version? What do you think? |
I'm fine with 3.0.1 😊 |
@cmodijk I went ahead and tagged it myself, see https://github.com/SimpleBus/MessageBus/releases/tag/v3.0.1 |
I See thats fine with me |
10478b6
to
b48f8f4
Compare
@cmodijk It's green! What do you think? |
a6d0215
to
11334c2
Compare
Please merge this! I can't wait to remove all that ugly |
@ruudk Did you read my earlier comment about merging this class with the current register compiler class #53 (comment)? Should we improve this now or create a separate issue to implement this later down the line any thoughts about this? |
@cmodijk I think it's better to do that later. First ship and release this :) |
Ready to merge? |
Merged! Thanks @ruudk I wil tag the latest version in a moment. |
Released the latest version @ruudk thanks for the work! |
Just tried to remove
😞 Edit: after a cache clear, the error is
Final edit: added |
🎉🎉🎉 I will update the docs soon ✌️ |
PR for docs: SimpleBus/docs#46 |
When a handler or subscriber is tagged and has an
__invoke
method it will be automatically registered. This is awesome.But what if you want to have 1 subscriber that handles 2 or more events?
Then you need to do manual work. Not nice!
This PR changes the AutoRegister compiler pass to search for all public methods and just register them as handlers/subscribers.
Tests are failing because of SimpleBus/message-bus#76 (comment)