Skip to content

Commit 4668ce2

Browse files
committed
Added exception
1 parent 663f93e commit 4668ce2

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

ClientFactory/ClientFactoryInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\HttplugBundle\ClientFactory;
44

55
use Http\Client\HttpClient;
6+
use Http\HttplugBundle\Exception\ClientWasNotCreated;
67

78
/**
89
* Interface ClientFactoryInterface.
@@ -15,8 +16,10 @@ interface ClientFactoryInterface
1516
* @param array $config
1617
*
1718
* @return HttpClient
19+
*
20+
* @throws ClientWasNotCreated
1821
*/
19-
public function configure(array $config = array());
22+
public function createClient(array $config = array());
2023

2124
/**
2225
* Return the name of the client.

ClientFactory/DummyFactory.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\HttplugBundle\ClientFactory;
44

55
use Http\Client\HttpClient;
6+
use Http\HttplugBundle\Exception\ClientWasNotCreated;
67

78
/**
89
* This class is used with the dependency injection when we register the service. It acts like a place holder and
@@ -13,21 +14,15 @@
1314
class DummyFactory implements ClientFactoryInterface
1415
{
1516
/**
16-
* Configure and return a client.
17-
*
18-
* @param array $config
19-
*
20-
* @return HttpClient
17+
* {@inheritdoc}
2118
*/
22-
public function configure(array $config = array())
19+
public function createClient(array $config = array())
2320
{
24-
return;
21+
throw new ClientWasNotCreated('The DummyFactory should not be used.');
2522
}
2623

2724
/**
28-
* Return the name of the client.
29-
*
30-
* @return string
25+
* {@inheritdoc}
3126
*/
3227
public function getName()
3328
{

ClientFactory/GenericClientFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class GenericClientFactory
1717
private $clientFactories;
1818

1919
/**
20-
* @param string $adapter
20+
* @param string $name
2121
* @param array $config
2222
*
2323
* @return HttpClient
2424
*/
25-
public function getClient($adapter, array $config = [])
25+
public function getClient($name, array $config = [])
2626
{
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));
2929
}
3030

31-
return $this->clientFactories[$adapter]->configure($config);
31+
return $this->clientFactories[$name]->createClient($config);
3232
}
3333

3434
/**

ClientFactory/Guzzle5Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Guzzle5Factory implements ClientFactoryInterface
1313
/**
1414
* {@inheritdoc}
1515
*/
16-
public function configure(array $config = array())
16+
public function createClient(array $config = array())
1717
{
1818
$client = new Client($config);
1919

ClientFactory/Guzzle6Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class Guzzle6Factory implements ClientFactoryInterface
1212
{
13-
public function configure(array $config = array())
13+
public function createClient(array $config = array())
1414
{
1515
$client = new Client($config);
1616

Exception/ClientWasNotCreated.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Http\HttplugBundle\Exception;
4+
5+
class ClientWasNotCreated extends \Exception
6+
{
7+
}

0 commit comments

Comments
 (0)