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

Commit

Permalink
Merge pull request #38 from csarrazi/feat-client-class
Browse files Browse the repository at this point in the history
Enable client class override
  • Loading branch information
csarrazi committed Jun 12, 2015
2 parents 07619a3 + 74c76c6 commit 079fc43
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private function createClientsNode()
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('class')->defaultValue('GuzzleHttp\Client')->end()
->variableNode('config')->end()
->arrayNode('subscribers')
->useAttributeAsKey('subscriber_name')
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/CsaGuzzleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function processCacheConfiguration(array $config, ContainerBuilder $cont
private function processClientsConfiguration(array $config, ContainerBuilder $container, Definition $descriptionFactory)
{
foreach ($config['clients'] as $name => $options) {
$client = new Definition($config['factory_class']);
$client = new Definition($options['class']);
$client->addArgument(isset($options['config']) ? $options['config'] : null);
$client->addTag(
SubscriberPass::CLIENT_TAG,
Expand Down
14 changes: 14 additions & 0 deletions src/Resources/doc/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ class MyController extends Controller
}
```

If you override your client's class, you can also set the class for your client:

```yml
csa_guzzle:
clients:
my_client:
class: AppBundle\Client
# ...
```

Of course, you need to make sure that your client class has no constructor arguments.

If you need to pass constructor arguments to your class, then you should use the tag syntax (see below).

Registering your own service
----------------------------

Expand Down
15 changes: 15 additions & 0 deletions src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public function testClientCreated()
);
}

public function testClientClassOverride()
{
$yaml = <<<YAML
clients:
foo:
class: AppBundle\Client
YAML;

$container = $this->createContainer($yaml);

$client = $container->getDefinition('csa_guzzle.client.foo');

$this->assertEquals('AppBundle\Client', $client->getClass());
}

public function testClientWithDescription()
{
$yaml = <<<YAML
Expand Down

0 comments on commit 079fc43

Please sign in to comment.