client-common icon indicating copy to clipboard operation
client-common copied to clipboard

Plugins vs PSR-15 middleware

Open dbu opened this issue 6 years ago • 2 comments

reading https://medium.com/@timoschinkel/implementing-psr-18-and-extending-it-with-middleware-b33eeceb2753 it occured to me that our PluginClient essentially mimiks PSR-15. should we migrate our plugins to middleware, or is there value in having them as they are?

dbu avatar Jan 28 '19 08:01 dbu

We cannot use PSR15 as it only accept a ServerRequestInterface (and it's way better, as client middleware does not have the same purpose as server middleware)

Also actually our plugin system rely on Promise as it's easy to switch from async to sync, but impossible to do otherwise (at least for php < 7.3)

However, i really believe in https://github.com/concurrent-php/ext-async which will allow us to use a PSR15 like interface for our plugin system (sync version) but still allow for async operation.

Also the $first variable in our plugin can be dropped (we just need to inject an http client into plugin using this variable)

So our interface can become something like :

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

interface Plugin {
    handleRequest(RequestInterface $request, ClientInterface $next): ResponseInterface;
}

joelwurtz avatar Jan 28 '19 15:01 joelwurtz

is there exist proposal for creating http client middleware for future PSR?

johnss avatar Nov 16 '19 16:11 johnss