File tree Expand file tree Collapse file tree 5 files changed +17
-42
lines changed Expand file tree Collapse file tree 5 files changed +17
-42
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,19 @@ async(static function () {
2525})();
2626```
2727
28+ Another major change in this release is that you no longer inject the event loop into the client. It now
29+ only uses the global loop accessor. This ensures the same event loop is used everywhere and makes creating
30+ the client a bit simpler:
31+
32+ ``` php
33+ use Http\Adapter\React\ReactFactory;
34+
35+ $reactHttp = ReactFactory::buildHttpClient();
36+ ```
37+
2838### Changed
2939
40+ - Removed injecting of the event loop and fully switched to using the global loop accessor (` Loop::get() ` )
3041- Use PHP 8.1 fibers as async mechanism.
3142- Detect supported PHP versions in range during CI instead of hardcoding them.
3243
Original file line number Diff line number Diff line change 1313 "require" : {
1414 "php" : " ^8.1" ,
1515 "php-http/httplug" : " ^2.0" ,
16- "react/http" : " ^1.0 " ,
17- "react/event-loop" : " ^1.2 " ,
16+ "react/http" : " ^1.8 " ,
17+ "react/event-loop" : " ^1.3 " ,
1818 "php-http/discovery" : " ^1.0" ,
1919 "react/async" : " ^4"
2020 },
Original file line number Diff line number Diff line change 66use Http \Client \HttpClient ;
77use Psr \Http \Message \RequestInterface ;
88use Psr \Http \Message \ResponseInterface ;
9- use React \EventLoop \LoopInterface ;
109use React \Http \Browser as ReactBrowser ;
1110
1211/**
@@ -23,26 +22,13 @@ class Client implements HttpClient, HttpAsyncClient
2322 */
2423 private $ client ;
2524
26- /**
27- * React event loop.
28- *
29- * @var LoopInterface
30- */
31- private $ loop ;
32-
3325 /**
3426 * Initialize the React client.
3527 */
3628 public function __construct (
37- LoopInterface $ loop = null ,
3829 ReactBrowser $ client = null
3930 ) {
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 ();
4632 }
4733
4834 /**
Original file line number Diff line number Diff line change 22
33namespace Http \Adapter \React ;
44
5- use React \EventLoop \Loop ;
6- use React \EventLoop \LoopInterface ;
75use React \Http \Browser ;
86use React \Socket \ConnectorInterface ;
97
1412 */
1513class ReactFactory
1614{
17- /**
18- * Build a react Event Loop.
19- */
20- public static function buildEventLoop (): LoopInterface
21- {
22- return Loop::get ();
23- }
24-
2515 /**
2616 * Build a React Http Client.
2717 *
2818 * @param ConnectorInterface|null $connector only pass this argument if you need to customize DNS
2919 * behaviour
3020 */
3121 public static function buildHttpClient (
32- LoopInterface $ loop ,
3322 ConnectorInterface $ connector = null
3423 ): Browser {
35- return (new Browser ($ loop , $ connector ))
24+ return (new Browser ($ connector ))
3625 ->withRejectErrorResponse (false )
3726 ->withFollowRedirects (false );
3827 }
Original file line number Diff line number Diff line change 44
55use Http \Adapter \React \ReactFactory ;
66use PHPUnit \Framework \TestCase ;
7- use React \EventLoop \LoopInterface ;
87use React \Http \Browser ;
98use React \Socket \ConnectorInterface ;
109
1615 */
1716class ReactFactoryTest extends TestCase
1817{
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-
2918 public function testBuildHttpClientWithConnector ()
3019 {
3120 /** @var ConnectorInterface $connector */
3221 $ connector = $ this ->getMockBuilder (ConnectorInterface::class)->getMock ();
33- $ client = ReactFactory::buildHttpClient ($ this -> loop , $ connector );
22+ $ client = ReactFactory::buildHttpClient ($ connector );
3423 $ this ->assertInstanceOf (Browser::class, $ client );
3524 }
3625
3726 public function testBuildHttpClientWithoutConnector ()
3827 {
39- $ client = ReactFactory::buildHttpClient ($ this -> loop );
28+ $ client = ReactFactory::buildHttpClient ();
4029 $ this ->assertInstanceOf (Browser::class, $ client );
4130 }
4231}
You can’t perform that action at this time.
0 commit comments