4
4
5
5
use React \EventLoop \LoopInterface ;
6
6
use React \EventLoop \Factory as EventLoopFactory ;
7
- use React \Dns \Resolver \Resolver as DnsResolver ;
8
- use React \Dns \Resolver \Factory as DnsResolverFactory ;
9
- use React \HttpClient \Client as HttpClient ;
10
- use React \HttpClient \Factory as HttpClientFactory ;
11
- use React \Socket \Connector ;
7
+ use React \Http \Browser ;
12
8
use React \Socket \ConnectorInterface ;
13
9
14
10
/**
15
11
* Factory wrapper for React instances.
16
12
*
17
- * @author Stéphane Hulard <stephane@hlrd.me >
13
+ * @author Stéphane Hulard <s.hulard@chstudio.fr >
18
14
*/
19
15
class ReactFactory
20
16
{
@@ -28,119 +24,21 @@ public static function buildEventLoop()
28
24
return EventLoopFactory::create ();
29
25
}
30
26
31
- /**
32
- * Build a React Dns Resolver.
33
- *
34
- * @param LoopInterface $loop
35
- * @param string $dns
36
- *
37
- * @return DnsResolver
38
- */
39
- public static function buildDnsResolver (
40
- LoopInterface $ loop ,
41
- $ dns = '8.8.8.8 '
42
- ) {
43
- $ factory = new DnsResolverFactory ();
44
-
45
- return $ factory ->createCached ($ dns , $ loop );
46
- }
47
-
48
- /**
49
- * @param LoopInterface $loop
50
- * @param DnsResolver|null $dns
51
- *
52
- * @return ConnectorInterface
53
- */
54
- public static function buildConnector (
55
- LoopInterface $ loop ,
56
- DnsResolver $ dns = null
57
- ) {
58
- return null !== $ dns
59
- ? new Connector ($ loop , ['dns ' => $ dns ])
60
- : new Connector ($ loop );
61
- }
62
-
63
27
/**
64
28
* Build a React Http Client.
65
29
*
66
- * @param LoopInterface $loop
67
- * @param ConnectorInterface|DnsResolver|null $connector Only pass this argument if you need to customize DNS
68
- * behaviour. With react http client v0.5, pass a connector,
69
- * with v0.4 this must be a DnsResolver.
30
+ * @param LoopInterface $loop
31
+ * @param ConnectorInterface|null $connector Only pass this argument if you need to customize DNS
32
+ * behaviour.
70
33
*
71
- * @return HttpClient
34
+ * @return Browser
72
35
*/
73
36
public static function buildHttpClient (
74
37
LoopInterface $ loop ,
75
- $ connector = null
76
- ) {
77
- if (class_exists (HttpClientFactory::class)) {
78
- // if HttpClientFactory class exists, use old behavior for backwards compatibility
79
- return static ::buildHttpClient04 ($ loop , $ connector );
80
- } else {
81
- return static ::buildHttpClient05 ($ loop , $ connector );
82
- }
83
- }
84
-
85
- /**
86
- * Builds a React Http client v0.4 style.
87
- *
88
- * @param LoopInterface $loop
89
- * @param DnsResolver|null $dns
90
- *
91
- * @return HttpClient
92
- */
93
- protected static function buildHttpClient04 (
94
- LoopInterface $ loop ,
95
- $ dns = null
96
- ) {
97
- // create dns resolver if one isn't provided
98
- if (null === $ dns ) {
99
- $ dns = static ::buildDnsResolver ($ loop );
100
- }
101
-
102
- // validate connector instance for proper error reporting
103
- if (!$ dns instanceof DnsResolver) {
104
- throw new \InvalidArgumentException ('For react http client v0.4, $dns must be an instance of DnsResolver ' );
105
- }
106
-
107
- $ factory = new HttpClientFactory ();
108
-
109
- return $ factory ->create ($ loop , $ dns );
110
- }
111
-
112
- /**
113
- * Builds a React Http client v0.5 style.
114
- *
115
- * @param LoopInterface $loop
116
- * @param DnsResolver|ConnectorInterface|null $connector
117
- *
118
- * @return HttpClient
119
- */
120
- protected static function buildHttpClient05 (
121
- LoopInterface $ loop ,
122
- $ connector = null
123
- ) {
124
- // build a connector with given DnsResolver if provided (old deprecated behavior)
125
- if ($ connector instanceof DnsResolver) {
126
- @trigger_error (
127
- sprintf (
128
- 'Passing a %s to buildHttpClient is deprecated since version 2.1.0 and will be removed in 3.0. If you need no specific behaviour, omit the $dns argument, otherwise pass a %s ' ,
129
- DnsResolver::class,
130
- ConnectorInterface::class
131
- ),
132
- E_USER_DEPRECATED
133
- );
134
- $ connector = static ::buildConnector ($ loop , $ connector );
135
- }
136
-
137
- // validate connector instance for proper error reporting
138
- if (null !== $ connector && !$ connector instanceof ConnectorInterface) {
139
- throw new \InvalidArgumentException (
140
- '$connector must be an instance of DnsResolver or ConnectorInterface '
141
- );
142
- }
143
-
144
- return new HttpClient ($ loop , $ connector );
38
+ ConnectorInterface $ connector = null
39
+ ): Browser {
40
+ return (new Browser ($ loop , $ connector ))
41
+ ->withRejectErrorResponse (false )
42
+ ->withFollowRedirects (false );
145
43
}
146
44
}
0 commit comments