diff --git a/src/BatchClient.php b/src/BatchClient.php index 2036355..1aa9950 100644 --- a/src/BatchClient.php +++ b/src/BatchClient.php @@ -5,6 +5,7 @@ use Http\Client\Exception; use Http\Client\HttpClient; use Http\Client\Common\Exception\BatchException; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; /** @@ -17,15 +18,19 @@ class BatchClient implements HttpClient { /** - * @var HttpClient + * @var HttpClient|ClientInterface */ private $client; /** - * @param HttpClient $client + * @param HttpClient|ClientInterface $client */ - public function __construct(HttpClient $client) + public function __construct($client) { + if (!($client instanceof HttpClient) && !($client instanceof ClientInterface)) { + throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface'); + } + $this->client = $client; } diff --git a/src/EmulatedHttpAsyncClient.php b/src/EmulatedHttpAsyncClient.php index 1b16316..39f89cc 100644 --- a/src/EmulatedHttpAsyncClient.php +++ b/src/EmulatedHttpAsyncClient.php @@ -4,6 +4,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * Emulates an async HTTP client. @@ -18,10 +19,14 @@ class EmulatedHttpAsyncClient implements HttpClient, HttpAsyncClient use HttpClientDecorator; /** - * @param HttpClient $httpClient + * @param HttpClient|ClientInterface $httpClient */ - public function __construct(HttpClient $httpClient) + public function __construct($httpClient) { + if (!($httpClient instanceof HttpClient) && !($httpClient instanceof ClientInterface)) { + throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface'); + } + $this->httpClient = $httpClient; } } diff --git a/src/FlexibleHttpClient.php b/src/FlexibleHttpClient.php index 58f8813..d0a6e88 100644 --- a/src/FlexibleHttpClient.php +++ b/src/FlexibleHttpClient.php @@ -4,6 +4,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * A flexible http client, which implements both interface and will emulate @@ -17,18 +18,18 @@ final class FlexibleHttpClient implements HttpClient, HttpAsyncClient use HttpAsyncClientDecorator; /** - * @param HttpClient|HttpAsyncClient $client + * @param HttpClient|HttpAsyncClient|ClientInterface $client */ public function __construct($client) { - if (!($client instanceof HttpClient) && !($client instanceof HttpAsyncClient)) { + if (!($client instanceof HttpClient) && !($client instanceof HttpAsyncClient) && !($client instanceof ClientInterface)) { throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient'); } $this->httpClient = $client; $this->httpAsyncClient = $client; - if (!($this->httpClient instanceof HttpClient)) { + if (!($this->httpClient instanceof HttpClient) && !($client instanceof ClientInterface)) { $this->httpClient = new EmulatedHttpClient($this->httpClient); } diff --git a/src/HttpClientDecorator.php b/src/HttpClientDecorator.php index a33d5ef..0b7e48e 100644 --- a/src/HttpClientDecorator.php +++ b/src/HttpClientDecorator.php @@ -3,6 +3,7 @@ namespace Http\Client\Common; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; /** @@ -13,7 +14,7 @@ trait HttpClientDecorator { /** - * @var HttpClient + * @var HttpClient|ClientInterface */ protected $httpClient; diff --git a/src/HttpMethodsClient.php b/src/HttpMethodsClient.php index 58804fc..c462c10 100644 --- a/src/HttpMethodsClient.php +++ b/src/HttpMethodsClient.php @@ -5,6 +5,7 @@ use Http\Client\Exception; use Http\Client\HttpClient; use Http\Message\RequestFactory; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -27,7 +28,7 @@ class HttpMethodsClient implements HttpClient { /** - * @var HttpClient + * @var HttpClient|ClientInterface */ private $httpClient; @@ -37,11 +38,15 @@ class HttpMethodsClient implements HttpClient private $requestFactory; /** - * @param HttpClient $httpClient The client to send requests with - * @param RequestFactory $requestFactory The message factory to create requests + * @param HttpClient|ClientInterface $httpClient The client to send requests with + * @param RequestFactory $requestFactory The message factory to create requests */ - public function __construct(HttpClient $httpClient, RequestFactory $requestFactory) + public function __construct($httpClient, RequestFactory $requestFactory) { + if (!($httpClient instanceof HttpClient) && !($httpClient instanceof ClientInterface)) { + throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface'); + } + $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; } diff --git a/src/PluginClient.php b/src/PluginClient.php index 93aea8f..8cedcf6 100644 --- a/src/PluginClient.php +++ b/src/PluginClient.php @@ -8,6 +8,7 @@ use Http\Client\HttpClient; use Http\Client\Promise\HttpFulfilledPromise; use Http\Client\Promise\HttpRejectedPromise; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -54,7 +55,7 @@ public function __construct($client, array $plugins = [], array $options = []) { if ($client instanceof HttpAsyncClient) { $this->client = $client; - } elseif ($client instanceof HttpClient) { + } elseif ($client instanceof HttpClient || $client instanceof ClientInterface) { $this->client = new EmulatedHttpAsyncClient($client); } else { throw new \RuntimeException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient'); diff --git a/src/PluginClientFactory.php b/src/PluginClientFactory.php index bd4c08f..cbea3e1 100644 --- a/src/PluginClientFactory.php +++ b/src/PluginClientFactory.php @@ -4,6 +4,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * Factory to create PluginClient instances. Using this factory instead of calling PluginClient constructor will enable @@ -35,9 +36,9 @@ public static function setFactory(callable $factory) } /** - * @param HttpClient|HttpAsyncClient $client - * @param Plugin[] $plugins - * @param array $options { + * @param HttpClient|HttpAsyncClient|ClientInterface $client + * @param Plugin[] $plugins + * @param array $options { * * @var string $client_name to give client a name which may be used when displaying client information like in * the HTTPlugBundle profiler.