Skip to content

Commit 2096327

Browse files
authored
Merge pull request #190 from GrahamCampbell/patch-1
Support the PSR17 request factory
2 parents d5ec7d7 + b41b922 commit 2096327

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"php-http/httplug": "^2.0",
1616
"php-http/message-factory": "^1.0",
1717
"php-http/message": "^1.6",
18-
"symfony/options-resolver": "^2.6 || ^3.4.20 || ~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0"
18+
"psr/http-factory": "^1.0",
19+
"psr/http-message": "^1.0",
20+
"symfony/options-resolver": "^2.6 || ^3.4.20 || ~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0",
21+
"symfony/polyfill-php80": "^1.17"
1922
},
2023
"require-dev": {
2124
"doctrine/instantiator": "^1.1",

src/HttpMethodsClient.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Http\Message\RequestFactory;
88
use Psr\Http\Client\ClientInterface;
9+
use Psr\Http\Message\RequestFactoryInterface;
910
use Psr\Http\Message\RequestInterface;
1011
use Psr\Http\Message\ResponseInterface;
1112

@@ -17,12 +18,21 @@ final class HttpMethodsClient implements HttpMethodsClientInterface
1718
private $httpClient;
1819

1920
/**
20-
* @var RequestFactory
21+
* @var RequestFactory|RequestFactoryInterface
2122
*/
2223
private $requestFactory;
2324

24-
public function __construct(ClientInterface $httpClient, RequestFactory $requestFactory)
25+
/**
26+
* @param RequestFactory|RequestFactoryInterface
27+
*/
28+
public function __construct(ClientInterface $httpClient, $requestFactory)
2529
{
30+
if (!$requestFactory instanceof RequestFactory && !$requestFactory instanceof RequestFactoryInterface) {
31+
throw new \TypeError(
32+
sprintf('%s::__construct(): Argument #2 ($requestFactory) must be of type %s|%s, %s given', self::class, RequestFactory::class, RequestFactoryInterface::class, get_debug_type($requestFactory))
33+
);
34+
}
35+
2636
$this->httpClient = $httpClient;
2737
$this->requestFactory = $requestFactory;
2838
}

0 commit comments

Comments
 (0)