php-http / client-common

Common HTTP Client implementations and tools for HTTPlug
http://httplug.io
MIT License
1.01k stars 53 forks source link

Plugins vs PSR-15 middleware #168

Open dbu opened 5 years ago

dbu commented 5 years ago

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?

joelwurtz commented 5 years ago

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;
}
johnss commented 4 years ago

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