Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
### Added

- Allow to configure the `AddPathPlugin` per client, under the `add_path` configuration key.
- Allow to configure clients with a `service` instead of a factory.

## 1.9.0 - 2018-03-06

Expand Down
10 changes: 10 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,22 @@ private function configureClients(ArrayNodeDefinition $root)
})
->thenInvalid('If you want to use the "config" key you must also specify a valid "factory".')
->end()
->validate()
->ifTrue(function ($config) {
return !empty($config['service']) && ('httplug.factory.auto' !== $config['factory'] || !empty($config['config']));
})
->thenInvalid('If you want to use the "service" key you cannot specify "factory" or "config".')
->end()
->children()
->scalarNode('factory')
->defaultValue('httplug.factory.auto')
->cannotBeEmpty()
->info('The service id of a factory to use when creating the adapter.')
->end()
->scalarNode('service')
->defaultNull()
->info('The service id of the client to use.')
->end()
->booleanNode('flexible_client')
->defaultFalse()
->info('Set to true to get the client wrapped in a FlexibleHttpClient which emulates async or sync behavior.')
Expand Down
16 changes: 10 additions & 6 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,16 @@ private function configureClient(ContainerBuilder $container, $clientName, array
}
}

$container
->register($serviceId.'.client', HttpClient::class)
->setFactory([new Reference($arguments['factory']), 'createClient'])
->addArgument($arguments['config'])
->setPublic(false)
;
if (empty($arguments['service'])) {
$container
->register($serviceId.'.client', HttpClient::class)
->setFactory([new Reference($arguments['factory']), 'createClient'])
->addArgument($arguments['config'])
->setPublic(false);
} else {
$container
->setAlias($serviceId.'.client', new Alias($arguments['service'], false));
}

$container
->register($serviceId, PluginClient::class)
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function testSupportsAllConfigFormats()
'test' => [
'factory' => 'httplug.factory.guzzle6',
'http_methods_client' => true,
'service' => null,
'flexible_client' => false,
'batch_client' => false,
'plugins' => [
Expand Down
15 changes: 15 additions & 0 deletions Tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ public function testCachePluginConfigCacheKeyGeneratorReference()
$this->assertSame('header_cache_key_generator', (string) $config['cache_key_generator']);
}

public function testUsingServiceKeyForClients()
{
$this->load([
'clients' => [
'acme' => [
'service' => 'my_custom_client',
],
],
]);

$client = $this->container->getAlias('httplug.client.acme.client');
$this->assertEquals('my_custom_client', (string) $client);
$this->assertFalse($client->isPublic());
}

private function verifyProfilingDisabled()
{
$def = $this->container->findDefinition('httplug.client');
Expand Down