Closed schnittstabil closed 7 years ago
Side Note: Thanks to @mindplay-dk, another argument wich reduces the need to support client-middlewares can be found at https://github.com/http-interop/http-middleware/issues/37#issuecomment-263861411
I'm in favor of changing the DelegateInterface
type hint to ServerRequestInterface
. It is not our place (in writing a server middleware spec) to make assumptions about what will or will not be useful to async middleware. Most likely the two specs would have different namespaces or the async middleware spec will supersede PSR-15 entirely.
Given that there is no one (to my knowledge) has started work on an async middleware spec, I would prefer that PSR-15 only refer to ServerRequestInterface
and never to RequestInterface
, as per #20.
@schnittstabil can you submit a PR for this please?
Today, I've tried to implement what @weierophinney has written at https://github.com/http-interop/http-middleware/pull/29#issuecomment-261097279:
At First, a quick reminder. I've suggested at #29:
About the stack trace
I've tried the following with Equip\Dispatch\MiddlewarePipe and middlewares/geolocation:
The resulting error:
The error message is misleading, the problem is not that I've called
Geolocation::process()
with the wrong argument, I've called$delegate->process
. Okay, it is easy for us to figure out, the real problem is mentioned at#1
and we may improve the error message, like I did below. But do we need to annoy novice middleware developers? Moreover, a novice may bark up the wrong tree and blame @oscarotero for his great middleware or would ask for help at stackoverflow, mailing lists and chat rooms :unamused:With
process(ServerRequestInterface $request)
:That would be the right one to me.
About middlewares with different signatures
How would such a client middleware may look like? I can only imagine 3 types @weierophinney may had in mind, they would be similar to:
The first one would be really strange – how should it work in a client container? The second one is not allowed in PHP – it is allowed in Java and C#, but neither in PHP 5 nor in PHP 7. Thus we end up with the third one.
What does that mean for a server middleware pipe? It cannot typehint to
callable
at the moment, thus it must usemixed
or offer different methods for each type.What we lose with
DelegateInterface::process(ServerRequestInterface)
A server middleware pipe will likely want to wrap the client middleware, and throw an appropriate a error:
Ugh, that is ugly. Btw, if both switch to
callables
it becomes much more readable in my opinion:But I don't want to talk about
callables
.This was just a hypothetical
ClientMiddleware
, if we think about promise-based middlewares (like Guzzle) or generator based middlewares (like my Cormy Bamboo), then we always need adapters. Therefore, I don't see any possible benefit of typehinting to client interfaces in server interfaces.