-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
4.x - Support For Slim Callables in MiddlewareDispatcher & Container Closure Autobinding #2779
4.x - Support For Slim Callables in MiddlewareDispatcher & Container Closure Autobinding #2779
Conversation
@l0gicgate I appreciate the quick response and the corresponding code. However, this doesn't actually allow the CallableResolver passed to It would be much more flexible for users if the CallableResolver itself was just injected in from |
@l0gicgate if we pass the callable resolver to the middleware dispatcher while creating the instance in the If not, I would pass the callable resolver and use it in the middleware dispatcher, as @SlvrEagle23 suggested. Or am I missing anything? |
This is great, greatly reducing the work that needs to be done to upgrade 4.x. |
Of course the |
The problem is that we can't use This PR is just so we can at least add back the ability to use Slim style callables Other than that, there isn't much more that can be done without overriding the entire |
@l0gicgate If you use the CallableResolver and add in a special condition for if the resolved instance is a |
@SlvrEagle23 Agree. @l0gicgate Do you think we need a |
@adriansuter I suppose we do, that’s the only component at the moment that you can’t drop in. @SlvrEagle23 the problem with adding a condition for We have to find a way to separate those concerns without BC changes (almost impossible) and without assumptions. It’s a hard problem to solve. |
Could we add an optional argument to the [RequestHandlerInterface::class => 'handle'] But in the middleware dispatcher, the map would be [MiddlewareInterface::class => 'process'] |
@adriansuter we can, but that breaks the interface. |
Not good. |
Then I guess your "duplication of code" is actually the only possible solution. Except maybe another new |
@adriansuter If you accept the premise that it's unacceptable to add a specific per-interface method overwrite to the CallableResolver (which is already done in this codebase as-is), then that would be the case. I know the talk about "BC breaks" is referring to the just-released Slim 4, but middleware not using the same CallableResolver as routes is itself a "BC break" from Slim 3, and it's that jump that I suspect will throw the most people off. I've already worked around the problem, but I feel like the duplication of code that is proposed in this solution is inelegant and completely closed to developer modifications, whereas the alternative both avoids duplication of code and allows for developer customization. I'm not a developer on the Slim project but as a senior PHP developer I would hope any framework I used would prioritize the latter. |
@SlvrEagle23 If we simply add per-interface conditions, then we would make assumptions. What happens, if a class implements multiple instances - then the callable resolver has to decide, which method should be called. |
@SlvrEagle23 then as a senior developer you should also know that separation of concerns is just as important and that further worsening the logic inside I addressed this in the PSR-15 PR when we were having the discussions and was shrugged off and now we’re having to deal with it post release, it’s rather frustrating to be honest. The only real solution is to modify the There should be 3 methods:
|
@l0gicgate If I had to choose between the two approaches, I'd rather see three interfaces ( |
@SlvrEagle23 separating all 3 now adds 3 more components to the App’s constructor, that seems a bit much, I understand why but sometimes practicality is more important. The constructor is already getting bloated as is and if we have to add |
@l0gicgate Fair enough. That works just as well in everyday use. |
@l0gicgate @SlvrEagle23 Agree. Unfortunately a BC. But better sooner than later. |
@adriansuter I think we can merge this in the mean time, release 4.1.0. Then we can introduce a BC in 4.2.0, nobody will suffer the BC unless they implemented their own CallableResolver (not that likely). |
This PR adds support for Slim callables when adding deferred style middleware:
$app->add('MyClass:customMethod`);
Fix for: #2770 (comment)
This PR also adds support for middleware callable Closure container auto-binding. Now callables are automatically bound to the container as they were in Slim 3.
Fix for: #2770 (comment)