From b41b922eeeff3331762e304eeea643a55bc1fd0b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 1 Jul 2020 10:44:12 +0100 Subject: [PATCH] Support the PSR17 request factory --- composer.json | 5 ++++- src/HttpMethodsClient.php | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6fae9c1..59b3e51 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,10 @@ "php-http/httplug": "^2.0", "php-http/message-factory": "^1.0", "php-http/message": "^1.6", - "symfony/options-resolver": "^2.6 || ^3.4.20 || ~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0" + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "symfony/options-resolver": "^2.6 || ^3.4.20 || ~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0", + "symfony/polyfill-php80": "^1.17" }, "require-dev": { "doctrine/instantiator": "^1.1", diff --git a/src/HttpMethodsClient.php b/src/HttpMethodsClient.php index 5b49c7c..bbe95be 100644 --- a/src/HttpMethodsClient.php +++ b/src/HttpMethodsClient.php @@ -6,6 +6,7 @@ use Http\Message\RequestFactory; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -17,12 +18,21 @@ final class HttpMethodsClient implements HttpMethodsClientInterface private $httpClient; /** - * @var RequestFactory + * @var RequestFactory|RequestFactoryInterface */ private $requestFactory; - public function __construct(ClientInterface $httpClient, RequestFactory $requestFactory) + /** + * @param RequestFactory|RequestFactoryInterface + */ + public function __construct(ClientInterface $httpClient, $requestFactory) { + if (!$requestFactory instanceof RequestFactory && !$requestFactory instanceof RequestFactoryInterface) { + throw new \TypeError( + sprintf('%s::__construct(): Argument #2 ($requestFactory) must be of type %s|%s, %s given', self::class, RequestFactory::class, RequestFactoryInterface::class, get_debug_type($requestFactory)) + ); + } + $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; }