Skip to content

Commit 5ab847d

Browse files
committed
use psr/http-factory instead of php-http/message-factory
1 parent 8bdbcd0 commit 5ab847d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

Diff for: composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
"optimize-autoloader": true,
4646
"preferred-install": {
4747
"*": "dist"
48+
},
49+
"allow-plugins": {
50+
"php-http/discovery": true
4851
}
4952
},
5053
"extra": {

Diff for: src/Rest/RestApiBrowser.php

+18-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Ubirak\RestApiBehatExtension\Rest;
44

5-
use Http\Client\HttpClient;
6-
use Http\Discovery\HttpClientDiscovery;
7-
use Http\Discovery\MessageFactoryDiscovery;
5+
use Http\Discovery\Psr17Factory;
6+
use Http\Discovery\Psr18ClientDiscovery;
7+
use Psr\Http\Client\ClientInterface;
8+
use Psr\Http\Message\RequestFactoryInterface;
89
use Psr\Http\Message\RequestInterface;
910
use Psr\Http\Message\ResponseInterface;
1011
use Tolerance\Operation\Callback;
@@ -15,7 +16,7 @@
1516

1617
class RestApiBrowser
1718
{
18-
/** @var HttpClient */
19+
/** @var ClientInterface */
1920
private $httpClient;
2021

2122
/** @var RequestInterface */
@@ -33,23 +34,23 @@ class RestApiBrowser
3334
/** @var string */
3435
private $host;
3536

36-
/** @var MessageFactoryDiscovery */
37+
/** @var RequestFactoryInterface */
3738
private $messageFactory;
3839

3940
/**
4041
* @param string $host
4142
*/
42-
public function __construct($host, HttpClient $httpClient = null)
43+
public function __construct($host, ClientInterface $httpClient = null)
4344
{
4445
$this->host = $host;
45-
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
46-
$this->messageFactory = MessageFactoryDiscovery::find();
46+
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
47+
$this->messageFactory = new Psr17Factory();
4748
}
4849

4950
/**
5051
* Allow to override the httpClient to use yours with specific middleware for example.
5152
*/
52-
public function useHttpClient(HttpClient $httpClient)
53+
public function useHttpClient(ClientInterface $httpClient)
5354
{
5455
$this->httpClient = $httpClient;
5556
}
@@ -105,7 +106,14 @@ public function sendRequest($method, $uri, $body = null)
105106
$this->setRequestHeader('Content-Type', $html->getContentTypeHeaderValue());
106107
}
107108

108-
$this->request = $this->messageFactory->createRequest($method, $uri, $this->requestHeaders, $body);
109+
$this->request = $this->messageFactory->createRequest($method, $uri);
110+
foreach ($this->requestHeaders as $keyHeader => $valueHeader) {
111+
$this->request = $this->request->withHeader($keyHeader, $valueHeader);
112+
}
113+
if (null !== $body) {
114+
$this->request = $this->request->withBody($this->messageFactory->createStream($body));
115+
}
116+
109117
$this->response = $this->httpClient->sendRequest($this->request);
110118
$this->requestHeaders = [];
111119

0 commit comments

Comments
 (0)