File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \Adapter ;
4
+
5
+ use React \EventLoop \LoopInterface ;
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 \Factory as HttpClientFactory ;
10
+ use React \HttpClient \Client as HttpClient ;
11
+
12
+ /**
13
+ * Factory wrapper for React instances
14
+ * @author Stéphane Hulard <[email protected] >
15
+ */
16
+ class ReactFactory
17
+ {
18
+ /**
19
+ * Build a react Event Loop
20
+ * @return LoopInterface
21
+ */
22
+ public static function buildEventLoop ()
23
+ {
24
+ return EventLoopFactory::create ();
25
+ }
26
+
27
+ /**
28
+ * Build a React Dns Resolver
29
+ * @param LoopInterface $loop
30
+ * @param string $dns
31
+ * @return DnsResolver
32
+ */
33
+ public static function buildDnsResolver (
34
+ LoopInterface $ loop ,
35
+ $ dns = '8.8.8.8 '
36
+ ) {
37
+ $ factory = new DnsResolverFactory ();
38
+ return $ factory ->createCached ($ dns , $ loop );
39
+ }
40
+
41
+ /**
42
+ * Build a React Http Client
43
+ * @param LoopInterface $loop
44
+ * @param Resolver $dns
45
+ * @return HttpClient
46
+ */
47
+ public static function buildHttpClient (
48
+ LoopInterface $ loop ,
49
+ DnsResolver $ dns = null
50
+ ) {
51
+ if ( null === $ dns ) {
52
+ $ dns = self ::buildDnsResolver ($ loop );
53
+ }
54
+
55
+ $ factory = new HttpClientFactory ();
56
+ return $ factory ->create ($ loop , $ dns );
57
+ }
58
+ }
You can’t perform that action at this time.
0 commit comments