http-interop / http-middleware

PSR-15 interfaces for HTTP Middleware
MIT License
73 stars 7 forks source link

Clarification of Misuse is Missing #66

Closed schnittstabil closed 7 years ago

schnittstabil commented 7 years ago

Note: Section 5.2 was updated and clarified a bit, which made discussions at #63 obsolet.

Current version:

5.2 Delegate Design

Why does the delegate conflict with middleware?

Both the middleware and delegate interface define a process method to discourage misuse of middleware as delegates.

As seen at #63, we cannot prevent that misuse just by naming both methods process:

class BottomMiddleware implements DelegateInterface, MiddlewareInterface
{
    function process(ServerRequestInterface $request, DelegateInterface $delegate = null)
    {
        return new Response();
    }
}

(https://3v4l.org/rgtcR proves that PHP allows that)

As a reader, I still don't know WHY it would be a misuse. And according to @crell's comment at the mailing list, I believe I'm not alone. Above is a bottom middleware and clearly does not violate SRP, moreover as far as I can see it is a counter example of any misuse I can think of.

Hence, I believe it's worth to add an explanation what kind of misuse we are talking about to the metadoc.

shadowhand commented 7 years ago

With the changes in #71 this is no longer an issue.