Closed chriseskow closed 8 years ago
the thing is, on routes and groups the callables need to be present in order to be added to the stack. Having this would require a significant rewrite of the middleware process, but it is possible.
I would imagine this could be done for 3.1
@chriseskow I made a modification to fix this here: https://github.com/mathmarques/Slim/tree/lazy-resolving-middleware The change: https://github.com/mathmarques/Slim/commit/99a85f9f1fbabfde730e160898da0024e56c7bb3
I'm justing trying to figure out why Slim needs to finalize() all routes via Router->finalize(). We just need to finalize the dispatched route.
I leave the Router->finalize() because of the Tests.
Something for 3.1.0. See https://github.com/slimphp/Slim/issues/1627
Fixed via #1716
Thanks for getting this done, guys! :sparkles:
I was playing around with Slim 3 and noticed that for group and route middleware, Slim will resolve the callable immediately when the middleware is added, instead of only when it is actually needed and called. This means if a particular route or group has a middleware defined by a DI container key which is potentially expensive to instantiate (e.g. because a database connection is injected into the constructor), it will be created on every request, not just requests that utilize that middleware.
Any chance that callable resolving for route- and group-level middleware could be deferred to when the middleware is executed, instead of when it is added? (App-level middleware shouldn't matter, since they run on every request anyway.)