| 1 |
<?php |
| 2 |
|
| 3 |
namespace Http\Discovery; |
| 4 |
|
| 5 |
use Psr\Http\Client\ClientInterface; |
| 6 |
use Psr\Http\Message\RequestFactoryInterface; |
| 7 |
use Psr\Http\Message\RequestInterface; |
| 8 |
use Psr\Http\Message\ResponseFactoryInterface; |
| 9 |
use Psr\Http\Message\ResponseInterface; |
| 10 |
use Psr\Http\Message\ServerRequestFactoryInterface; |
| 11 |
use Psr\Http\Message\StreamFactoryInterface; |
| 12 |
use Psr\Http\Message\UploadedFileFactoryInterface; |
| 13 |
use Psr\Http\Message\UriFactoryInterface; |
| 14 |
|
| 15 |
/** |
| 16 |
* A generic PSR-18 and PSR-17 implementation. |
| 17 |
* |
| 18 |
* You can create this class with concrete client and factory instances |
| 19 |
* or let it use discovery to find suitable implementations as needed. |
| 20 |
* |
| 21 |
* @author Nicolas Grekas <p@tchwork.com> |
| 22 |
*/ |
| 23 |
class Psr18Client extends Psr17Factory implements ClientInterface |
| 24 |
{ |
| 25 |
private $client; |
| 26 |
|
| 27 |
public function __construct( |
| 28 |
?ClientInterface $client = null, |
| 29 |
?RequestFactoryInterface $requestFactory = null, |
| 30 |
?ResponseFactoryInterface $responseFactory = null, |
| 31 |
?ServerRequestFactoryInterface $serverRequestFactory = null, |
| 32 |
?StreamFactoryInterface $streamFactory = null, |
| 33 |
?UploadedFileFactoryInterface $uploadedFileFactory = null, |
| 34 |
?UriFactoryInterface $uriFactory = null |
| 35 |
) { |
| 36 |
parent::__construct($requestFactory, $responseFactory, $serverRequestFactory, $streamFactory, $uploadedFileFactory, $uriFactory); |
| 37 |
|
| 38 |
$this->client = $client ?? Psr18ClientDiscovery::find(); |
| 39 |
} |
| 40 |
|
| 41 |
public function sendRequest(RequestInterface $request): ResponseInterface |
| 42 |
{ |
| 43 |
return $this->client->sendRequest($request); |
| 44 |
} |
| 45 |
} |
| 46 |
|