File tree Expand file tree Collapse file tree 3 files changed +5
-36
lines changed Expand file tree Collapse file tree 3 files changed +5
-36
lines changed Original file line number Diff line number Diff line change 6
6
use Http \Client \HttpClient ;
7
7
use Psr \Http \Message \RequestInterface ;
8
8
use Psr \Http \Message \ResponseInterface ;
9
+ use React \EventLoop \Loop ;
9
10
use React \EventLoop \LoopInterface ;
10
11
use React \Http \Browser as ReactBrowser ;
11
12
@@ -23,26 +24,13 @@ class Client implements HttpClient, HttpAsyncClient
23
24
*/
24
25
private $ client ;
25
26
26
- /**
27
- * React event loop.
28
- *
29
- * @var LoopInterface
30
- */
31
- private $ loop ;
32
-
33
27
/**
34
28
* Initialize the React client.
35
29
*/
36
30
public function __construct (
37
- LoopInterface $ loop = null ,
38
31
ReactBrowser $ client = null
39
32
) {
40
- if (null !== $ client && null === $ loop ) {
41
- throw new \RuntimeException ('You must give a LoopInterface instance with the Client ' );
42
- }
43
-
44
- $ this ->loop = $ loop ?: ReactFactory::buildEventLoop ();
45
- $ this ->client = $ client ?: ReactFactory::buildHttpClient ($ this ->loop );
33
+ $ this ->client = $ client ?: ReactFactory::buildHttpClient ();
46
34
}
47
35
48
36
/**
Original file line number Diff line number Diff line change 14
14
*/
15
15
class ReactFactory
16
16
{
17
- /**
18
- * Build a react Event Loop.
19
- */
20
- public static function buildEventLoop (): LoopInterface
21
- {
22
- return Loop::get ();
23
- }
24
-
25
17
/**
26
18
* Build a React Http Client.
27
19
*
28
20
* @param ConnectorInterface|null $connector only pass this argument if you need to customize DNS
29
21
* behaviour
30
22
*/
31
23
public static function buildHttpClient (
32
- LoopInterface $ loop ,
33
24
ConnectorInterface $ connector = null
34
25
): Browser {
35
- return (new Browser ($ loop , $ connector ))
26
+ return (new Browser ($ connector ))
36
27
->withRejectErrorResponse (false )
37
28
->withFollowRedirects (false );
38
29
}
Original file line number Diff line number Diff line change 16
16
*/
17
17
class ReactFactoryTest extends TestCase
18
18
{
19
- /**
20
- * @var \React\EventLoop\LoopInterface
21
- */
22
- private $ loop ;
23
-
24
- protected function setUp (): void
25
- {
26
- $ this ->loop = $ this ->getMockBuilder (LoopInterface::class)->getMock ();
27
- }
28
-
29
19
public function testBuildHttpClientWithConnector ()
30
20
{
31
21
/** @var ConnectorInterface $connector */
32
22
$ connector = $ this ->getMockBuilder (ConnectorInterface::class)->getMock ();
33
- $ client = ReactFactory::buildHttpClient ($ this -> loop , $ connector );
23
+ $ client = ReactFactory::buildHttpClient ($ connector );
34
24
$ this ->assertInstanceOf (Browser::class, $ client );
35
25
}
36
26
37
27
public function testBuildHttpClientWithoutConnector ()
38
28
{
39
- $ client = ReactFactory::buildHttpClient ($ this -> loop );
29
+ $ client = ReactFactory::buildHttpClient ();
40
30
$ this ->assertInstanceOf (Browser::class, $ client );
41
31
}
42
32
}
You can’t perform that action at this time.
0 commit comments