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