Closed mmoreram closed 4 years ago
Hi, thanks for the suggestion! Having considered it, this doesn't feel consistent with the way typing is done through out the broader PHP ecosystem. Also, while the interface wouldn't be present, the implemented middleware would still need to implicitly follow the same interface or a very similar one, making the decoupling a bit of an illusion.
If folks are very concerned about the middleware interface inside their domain layer (and I'm not sure middleware counts as domain layer personally but alright) then I would recommend they make a bridge adapter for their middleware interface to the Tactician middleware interface.
Thanks again for taking the time to write up a nice proposal, but I think it's not quite the right fit. :)
Since Tactician is being used in tons of projects, and some of them are trying to uncouple as much as possible the domain from the infrastructure and external libraries, I think that could be interesting to add a small layer here for those willing to add custom Middleware instances without having to implement the interface.
As the bus is built during the compilation of the container, checking that the handle method exists as it should exists could be done in terms of Reflection ways, instead of having to implement the interface.
Of course, I'm not saying to stop using the Interface, but softly allow not using it.
In terms of implementation, I would say that a small wrapper would be enough, checking if the defined chain Middleware instance implements the interface, and using a small wrapper class otherwise. We could enable this feature by using a false-by-default configuration flag.