File tree Expand file tree Collapse file tree 5 files changed +147
-2
lines changed Expand file tree Collapse file tree 5 files changed +147
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \HttplugBundle \ClientFactory ;
4
+
5
+ use Http \Client \Curl \Client ;
6
+ use Http \Message \MessageFactory ;
7
+ use Http \Message \StreamFactory ;
8
+
9
+ /**
10
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
11
+ */
12
+ class CurlFactory implements ClientFactory
13
+ {
14
+ /**
15
+ * @var MessageFactory
16
+ */
17
+ private $ messageFactory ;
18
+
19
+ /**
20
+ * @var StreamFactory
21
+ */
22
+ private $ streamFactory ;
23
+
24
+ /**
25
+ * @param MessageFactory $messageFactory
26
+ * @param StreamFactory $streamFactory
27
+ */
28
+ public function __construct (MessageFactory $ messageFactory , StreamFactory $ streamFactory )
29
+ {
30
+ $ this ->messageFactory = $ messageFactory ;
31
+ $ this ->streamFactory = $ streamFactory ;
32
+ }
33
+
34
+ /**
35
+ * {@inheritdoc}
36
+ */
37
+ public function createClient (array $ config = [])
38
+ {
39
+ if (!class_exists ('Http\Client\Curl\Client ' )) {
40
+ throw new \LogicException ('To use the Curl client you need to install the "php-http/curl-client" package. ' );
41
+ }
42
+
43
+ return new Client ($ this ->messageFactory , $ this ->streamFactory , $ config );
44
+ }
45
+ }
Original file line number Diff line number Diff line change 4
4
5
5
use GuzzleHttp \Client ;
6
6
use Http \Adapter \Guzzle5 \Client as Adapter ;
7
+ use Http \Message \MessageFactory ;
7
8
8
9
/**
9
10
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
10
11
*/
11
12
class Guzzle5Factory implements ClientFactory
12
13
{
14
+ /**
15
+ * @var MessageFactory
16
+ */
17
+ private $ messageFactory ;
18
+
19
+ /**
20
+ * @param MessageFactory $messageFactory
21
+ */
22
+ public function __construct (MessageFactory $ messageFactory )
23
+ {
24
+ $ this ->messageFactory = $ messageFactory ;
25
+ }
26
+
13
27
/**
14
28
* {@inheritdoc}
15
29
*/
@@ -21,6 +35,6 @@ public function createClient(array $config = [])
21
35
22
36
$ client = new Client ($ config );
23
37
24
- return new Adapter ($ client );
38
+ return new Adapter ($ client, $ this -> messageFactory );
25
39
}
26
40
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \HttplugBundle \ClientFactory ;
4
+
5
+ use Http \Adapter \React \Client ;
6
+ use Http \Message \MessageFactory ;
7
+
8
+ /**
9
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
10
+ */
11
+ class ReactFactory implements ClientFactory
12
+ {
13
+ /**
14
+ * @var MessageFactory
15
+ */
16
+ private $ messageFactory ;
17
+
18
+ /**
19
+ * @param MessageFactory $messageFactory
20
+ */
21
+ public function __construct (MessageFactory $ messageFactory )
22
+ {
23
+ $ this ->messageFactory = $ messageFactory ;
24
+ }
25
+
26
+ /**
27
+ * {@inheritdoc}
28
+ */
29
+ public function createClient (array $ config = [])
30
+ {
31
+ if (!class_exists ('Http\Adapter\React\Client ' )) {
32
+ throw new \LogicException ('To use the React adapter you need to install the "php-http/react-adapter" package. ' );
33
+ }
34
+
35
+ return new Client ($ this ->messageFactory );
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \HttplugBundle \ClientFactory ;
4
+
5
+ use Http \Client \Socket \Client ;
6
+ use Http \Message \MessageFactory ;
7
+
8
+ /**
9
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
10
+ */
11
+ class SocketFactory implements ClientFactory
12
+ {
13
+ /**
14
+ * @var MessageFactory
15
+ */
16
+ private $ messageFactory ;
17
+
18
+ /**
19
+ * @param MessageFactory $messageFactory
20
+ */
21
+ public function __construct (MessageFactory $ messageFactory )
22
+ {
23
+ $ this ->messageFactory = $ messageFactory ;
24
+ }
25
+
26
+ /**
27
+ * {@inheritdoc}
28
+ */
29
+ public function createClient (array $ config = [])
30
+ {
31
+ if (!class_exists ('Http\Client\Socket\Client ' )) {
32
+ throw new \LogicException ('To use the Socket client you need to install the "php-http/socket-client" package. ' );
33
+ }
34
+
35
+ return new Client ($ this ->messageFactory , $ config );
36
+ }
37
+ }
Original file line number Diff line number Diff line change 6
6
<services >
7
7
8
8
<!-- ClientFactories -->
9
- <service id =" httplug.factory.guzzle5" class =" Http\HttplugBundle\ClientFactory\Guzzle5Factory" public =" false" />
9
+ <service id =" httplug.factory.curl" class =" Http\HttplugBundle\ClientFactory\CurlFactory" public =" false" >
10
+ <argument type =" service" id =" httplug.message_factory" />
11
+ <argument type =" service" id =" httplug.stream_factory" />
12
+ </service >
13
+ <service id =" httplug.factory.guzzle5" class =" Http\HttplugBundle\ClientFactory\Guzzle5Factory" public =" false" >
14
+ <argument type =" service" id =" httplug.message_factory" />
15
+ </service >
10
16
<service id =" httplug.factory.guzzle6" class =" Http\HttplugBundle\ClientFactory\Guzzle6Factory" public =" false" />
17
+ <service id =" httplug.factory.react" class =" Http\HttplugBundle\ClientFactory\ReactFactory" public =" false" >
18
+ <argument type =" service" id =" httplug.message_factory" />
19
+ </service >
20
+ <service id =" httplug.factory.socket" class =" Http\HttplugBundle\ClientFactory\SocketFactory" public =" false" >
21
+ <argument type =" service" id =" httplug.message_factory" />
22
+ </service >
11
23
</services >
12
24
</container >
You can’t perform that action at this time.
0 commit comments