Skip to content

Commit 2c85746

Browse files
committed
Add configuration option to disable registration of default client
1 parent d053921 commit 2c85746

File tree

8 files changed

+24
-0
lines changed

8 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1010
BatchClientInterface if they are enabled on the default/first client.
1111
(Only available with Httplug 2)
1212
- Configuration for the content_type plugin
13+
- Configuration option `register_default_client` to allow disabling registering a
14+
default client. This will prevent autowiring the default client without knowing it.
1315

1416
### Changed
1517

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public function getConfigTreeBuilder()
108108
->end()
109109
->fixXmlConfig('client')
110110
->children()
111+
->booleanNode('register_default_client')
112+
->defaultTrue()
113+
->info('Set to false to not register the default client.')
114+
->end()
111115
->arrayNode('main_alias')
112116
->addDefaultsIfNotSet()
113117
->info('Configure which service the main alias point to.')

src/DependencyInjection/HttplugExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function load(array $configs, ContainerBuilder $container)
8787
$this->configureClients($container, $config);
8888
$this->configurePlugins($container, $config['plugins']); // must be after clients, as clients.X.plugins might use plugins as templates that will be removed
8989
$this->configureAutoDiscoveryClients($container, $config);
90+
91+
if (!$config['register_default_client']) {
92+
$container->removeDefinition('httplug.client.default');
93+
}
9094
}
9195

9296
/**

tests/Functional/DiscoveryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ public function testNoDiscoveryFallbacks()
7171
$clientDefinition = $this->container->getDefinition('httplug.client.default');
7272
$this->assertEquals([HttpClientDiscovery::class, 'find'], $clientDefinition->getFactory());
7373
}
74+
75+
public function testDisableDefaultClient()
76+
{
77+
$this->load([
78+
'register_default_client' => false,
79+
]);
80+
81+
$this->assertContainerBuilderNotHasService('httplug.client.default');
82+
}
7483
}

tests/Resources/Fixtures/config/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
$container->loadFromExtension('httplug', [
4+
'register_default_client' => false,
45
'main_alias' => [
56
'client' => 'my_client',
67
'message_factory' => 'my_message_factory',

tests/Resources/Fixtures/config/full.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<container xmlns="http://symfony.com/schema/dic/services">
33

44
<config xmlns="http://example.org/schema/dic/httplug">
5+
<register-default-client>false</register-default-client>
56
<main-alias>
67
<client>my_client</client>
78
<message-factory>my_message_factory</message-factory>

tests/Resources/Fixtures/config/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
httplug:
2+
register_default_client: false
23
main_alias:
34
client: my_client
45
message_factory: my_message_factory

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
1313
{
1414
private $emptyConfig = [
15+
'register_default_client' => true,
1516
'main_alias' => [
1617
'client' => 'httplug.client.default',
1718
'message_factory' => 'httplug.message_factory.default',
@@ -102,6 +103,7 @@ public function testEmptyConfiguration()
102103
public function testSupportsAllConfigFormats()
103104
{
104105
$expectedConfiguration = [
106+
'register_default_client' => false,
105107
'main_alias' => [
106108
'client' => 'my_client',
107109
'message_factory' => 'my_message_factory',

0 commit comments

Comments
 (0)