Skip to content

Commit bfcc975

Browse files
committed
Merge pull request #11 from php-http/discovery
Discovery support
2 parents 7112f8c + 96b4b7a commit bfcc975

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

Diff for: composer.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
"php-http/httplug": "^1.0",
1616
"react/http-client": "^0.4.8",
1717
"react/dns": "^0.4.1",
18-
"react/stream": "^0.4.3"
18+
"react/stream": "^0.4.3",
19+
"php-http/discovery": "^0.8"
1920
},
2021
"require-dev": {
21-
"guzzlehttp/psr7": "^1.0",
22-
"php-http/adapter-integration-tests": "^0.3.1",
23-
"puli/composer-plugin": "1.0.0-beta9"
22+
"php-http/adapter-integration-tests": "^0.4"
2423
},
2524
"autoload": {
2625
"psr-4": {

Diff for: src/Client.php

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

33
namespace Http\Adapter\React;
44

5+
use Http\Discovery\MessageFactoryDiscovery;
56
use Psr\Http\Message\ResponseInterface;
67
use React\EventLoop\LoopInterface;
78
use React\Promise\Deferred;
@@ -38,7 +39,7 @@ class Client implements HttpClient, HttpAsyncClient
3839
private $loop;
3940

4041
/**
41-
* HttpPlug message factory.
42+
* HTTPlug message factory.
4243
*
4344
* @var MessageFactory
4445
*/
@@ -47,12 +48,12 @@ class Client implements HttpClient, HttpAsyncClient
4748
/**
4849
* Initialize the React client.
4950
*
50-
* @param MessageFactory $messageFactory
51-
* @param LoopInterface|null $loop React Event loop
52-
* @param ReactClient $client React client to use
51+
* @param MessageFactory|null $messageFactory
52+
* @param LoopInterface|null $loop React Event loop
53+
* @param ReactClient|null $client React client to use
5354
*/
5455
public function __construct(
55-
MessageFactory $messageFactory,
56+
MessageFactory $messageFactory = null,
5657
LoopInterface $loop = null,
5758
ReactClient $client = null
5859
) {
@@ -64,7 +65,7 @@ public function __construct(
6465
$this->loop = (null !== $loop) ?: ReactFactory::buildEventLoop();
6566
$this->client = (null !== $client) ?: ReactFactory::buildHttpClient($this->loop);
6667

67-
$this->messageFactory = $messageFactory;
68+
$this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find();
6869
}
6970

7071
/**

Diff for: tests/AsyncClientTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Http\Adapter\React\Tests;
44

55
use Http\Client\HttpClient;
6-
use Http\Discovery\MessageFactoryDiscovery;
76
use Http\Client\Tests\HttpAsyncClientTest;
87
use Http\Adapter\React\Client;
8+
use Http\Message\MessageFactory\GuzzleMessageFactory;
99

1010
/**
1111
* @author Stéphane Hulard <[email protected]>
@@ -17,7 +17,6 @@ class AsyncClientTest extends HttpAsyncClientTest
1717
*/
1818
protected function createHttpAsyncClient()
1919
{
20-
$messageFactory = MessageFactoryDiscovery::find();
21-
return new Client($messageFactory);
20+
return new Client(new GuzzleMessageFactory());
2221
}
2322
}

Diff for: tests/ClientTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Http\Client\HttpClient;
66
use Http\Client\Tests\HttpClientTest;
77
use Http\Adapter\React\Client;
8-
use Http\Discovery\MessageFactoryDiscovery;
8+
use Http\Message\MessageFactory\GuzzleMessageFactory;
99

1010
/**
1111
* @author Stéphane Hulard <[email protected]>
@@ -17,7 +17,6 @@ class ClientTest extends HttpClientTest
1717
*/
1818
protected function createHttpAdapter()
1919
{
20-
$messageFactory = MessageFactoryDiscovery::find();
21-
return new Client($messageFactory);
20+
return new Client(new GuzzleMessageFactory());
2221
}
2322
}

0 commit comments

Comments
 (0)