Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 079fc43

Browse files
committed
Merge pull request #38 from csarrazi/feat-client-class
Enable client class override
2 parents 07619a3 + 74c76c6 commit 079fc43

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private function createClientsNode()
8888
->useAttributeAsKey('name')
8989
->prototype('array')
9090
->children()
91+
->scalarNode('class')->defaultValue('GuzzleHttp\Client')->end()
9192
->variableNode('config')->end()
9293
->arrayNode('subscribers')
9394
->useAttributeAsKey('subscriber_name')

src/DependencyInjection/CsaGuzzleExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function processCacheConfiguration(array $config, ContainerBuilder $cont
9797
private function processClientsConfiguration(array $config, ContainerBuilder $container, Definition $descriptionFactory)
9898
{
9999
foreach ($config['clients'] as $name => $options) {
100-
$client = new Definition($config['factory_class']);
100+
$client = new Definition($options['class']);
101101
$client->addArgument(isset($options['config']) ? $options['config'] : null);
102102
$client->addTag(
103103
SubscriberPass::CLIENT_TAG,

src/Resources/doc/clients.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ class MyController extends Controller
3939
}
4040
```
4141

42+
If you override your client's class, you can also set the class for your client:
43+
44+
```yml
45+
csa_guzzle:
46+
clients:
47+
my_client:
48+
class: AppBundle\Client
49+
# ...
50+
```
51+
52+
Of course, you need to make sure that your client class has no constructor arguments.
53+
54+
If you need to pass constructor arguments to your class, then you should use the tag syntax (see below).
55+
4256
Registering your own service
4357
----------------------------
4458

src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public function testClientCreated()
4949
);
5050
}
5151

52+
public function testClientClassOverride()
53+
{
54+
$yaml = <<<YAML
55+
clients:
56+
foo:
57+
class: AppBundle\Client
58+
YAML;
59+
60+
$container = $this->createContainer($yaml);
61+
62+
$client = $container->getDefinition('csa_guzzle.client.foo');
63+
64+
$this->assertEquals('AppBundle\Client', $client->getClass());
65+
}
66+
5267
public function testClientWithDescription()
5368
{
5469
$yaml = <<<YAML

0 commit comments

Comments
 (0)