diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 72a7ff05..a85d6b6d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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') diff --git a/src/DependencyInjection/CsaGuzzleExtension.php b/src/DependencyInjection/CsaGuzzleExtension.php index 4c44243b..c3d4b41e 100644 --- a/src/DependencyInjection/CsaGuzzleExtension.php +++ b/src/DependencyInjection/CsaGuzzleExtension.php @@ -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, diff --git a/src/Resources/doc/clients.md b/src/Resources/doc/clients.md index 211290c2..582bfc3c 100644 --- a/src/Resources/doc/clients.md +++ b/src/Resources/doc/clients.md @@ -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 ---------------------------- diff --git a/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php b/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php index 656b0953..a6b90a29 100644 --- a/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php +++ b/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php @@ -49,6 +49,21 @@ public function testClientCreated() ); } + public function testClientClassOverride() + { + $yaml = <<createContainer($yaml); + + $client = $container->getDefinition('csa_guzzle.client.foo'); + + $this->assertEquals('AppBundle\Client', $client->getClass()); + } + public function testClientWithDescription() { $yaml = <<