File tree Expand file tree Collapse file tree 6 files changed +23
-18
lines changed Expand file tree Collapse file tree 6 files changed +23
-18
lines changed Original file line number Diff line number Diff line change 3
3
namespace Http \HttplugBundle \ClientFactory ;
4
4
5
5
use Http \Client \HttpClient ;
6
+ use Http \HttplugBundle \Exception \ClientWasNotCreated ;
6
7
7
8
/**
8
9
* Interface ClientFactoryInterface.
@@ -15,8 +16,10 @@ interface ClientFactoryInterface
15
16
* @param array $config
16
17
*
17
18
* @return HttpClient
19
+ *
20
+ * @throws ClientWasNotCreated
18
21
*/
19
- public function configure (array $ config = array ());
22
+ public function createClient (array $ config = array ());
20
23
21
24
/**
22
25
* Return the name of the client.
Original file line number Diff line number Diff line change 3
3
namespace Http \HttplugBundle \ClientFactory ;
4
4
5
5
use Http \Client \HttpClient ;
6
+ use Http \HttplugBundle \Exception \ClientWasNotCreated ;
6
7
7
8
/**
8
9
* This class is used with the dependency injection when we register the service. It acts like a place holder and
13
14
class DummyFactory implements ClientFactoryInterface
14
15
{
15
16
/**
16
- * Configure and return a client.
17
- *
18
- * @param array $config
19
- *
20
- * @return HttpClient
17
+ * {@inheritdoc}
21
18
*/
22
- public function configure (array $ config = array ())
19
+ public function createClient (array $ config = array ())
23
20
{
24
- return ;
21
+ throw new ClientWasNotCreated ( ' The DummyFactory should not be used. ' ) ;
25
22
}
26
23
27
24
/**
28
- * Return the name of the client.
29
- *
30
- * @return string
25
+ * {@inheritdoc}
31
26
*/
32
27
public function getName ()
33
28
{
Original file line number Diff line number Diff line change @@ -17,18 +17,18 @@ class GenericClientFactory
17
17
private $ clientFactories ;
18
18
19
19
/**
20
- * @param string $adapter
20
+ * @param string $name
21
21
* @param array $config
22
22
*
23
23
* @return HttpClient
24
24
*/
25
- public function getClient ($ adapter , array $ config = [])
25
+ public function getClient ($ name , array $ config = [])
26
26
{
27
- if (!isset ($ this ->clientFactories [$ adapter ])) {
28
- throw new \InvalidArgumentException (sprintf ('No configurator named %s was found. ' , $ adapter ));
27
+ if (!isset ($ this ->clientFactories [$ name ])) {
28
+ throw new \InvalidArgumentException (sprintf ('No configurator named %s was found. ' , $ name ));
29
29
}
30
30
31
- return $ this ->clientFactories [$ adapter ]->configure ($ config );
31
+ return $ this ->clientFactories [$ name ]->createClient ($ config );
32
32
}
33
33
34
34
/**
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class Guzzle5Factory implements ClientFactoryInterface
13
13
/**
14
14
* {@inheritdoc}
15
15
*/
16
- public function configure (array $ config = array ())
16
+ public function createClient (array $ config = array ())
17
17
{
18
18
$ client = new Client ($ config );
19
19
Original file line number Diff line number Diff line change 10
10
*/
11
11
class Guzzle6Factory implements ClientFactoryInterface
12
12
{
13
- public function configure (array $ config = array ())
13
+ public function createClient (array $ config = array ())
14
14
{
15
15
$ client = new Client ($ config );
16
16
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \HttplugBundle \Exception ;
4
+
5
+ class ClientWasNotCreated extends \Exception
6
+ {
7
+ }
You can’t perform that action at this time.
0 commit comments