| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace Jasny\Dummy; |
||
| 4 | |||
| 5 | use Http\Client\Common\Plugin as HttpPlugin; |
||
| 6 | use Http\Promise\Promise as HttpPromise; |
||
| 7 | use Psr\Http\Message\RequestInterface; |
||
| 8 | use Psr\Http\Message\ResponseInterface; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Dummy middleware for PSR-7 HTTP clients. |
||
| 12 | */ |
||
| 13 | class ClientMiddleware |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Return a callback that can be used as double pass middleware. |
||
| 17 | * |
||
| 18 | * @return callable |
||
| 19 | */ |
||
| 20 | 1 | public function asDoublePass(): callable |
|
| 21 | { |
||
| 22 | return function (RequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface { |
||
| 23 | 1 | return $next($request, $response); |
|
| 24 | 1 | }; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Return a callback that can be used as Guzzle middleware. |
||
| 29 | * @see http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html |
||
| 30 | * |
||
| 31 | * @return callable |
||
| 32 | */ |
||
| 33 | 2 | public function forGuzzle(): callable |
|
| 34 | { |
||
| 35 | return function (callable $handler) { |
||
| 36 | return function (RequestInterface $request, array $options) use ($handler) { |
||
| 37 | 2 | return $handler($request, $options); |
|
| 38 | 2 | }; |
|
| 39 | 2 | }; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Create a version of this middleware that can be used in HTTPlug. |
||
| 44 | * @see http://docs.php-http.org/en/latest/plugins/introduction.html |
||
| 45 | * |
||
| 46 | * @return self&HttpPlugin |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 47 | */ |
||
| 48 | public function forHttplug(): HttpPlugin |
||
| 49 | { |
||
| 50 | return new class () extends ClientMiddleware implements HttpPlugin { |
||
| 51 | 1 | public function handleRequest(RequestInterface $request, callable $next, callable $first): HttpPromise |
|
| 52 | { |
||
| 53 | 1 | return $next($request); |
|
| 54 | } |
||
| 55 | }; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |