Skip to content

Commit 2804464

Browse files
committed
Add default_client configuration option
Added `default_client` configuration option to disable assigning the first client as default client and to remove the default client service.
1 parent 51173c3 commit 2804464

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
# Version 2
66

7+
# 2.2.0
8+
9+
- Added `default_client` configuration option to disable assigning the first client as default client and to remove the default client service.
10+
711
# 2.1.0 - 2024-11-24
812

913
- Added [PluginConfigurator](https://docs.php-http.org/en/latest/integrations/symfony-bundle.html#configure-a-custom-plugin)

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public function getConfigTreeBuilder(): TreeBuilder
7979
->defaultTrue()
8080
->info('Set to false to not autowire ClientInterface and HttpAsyncClient.')
8181
->end()
82+
->booleanNode('default_client')
83+
->defaultTrue()
84+
->info('Set to false to disable assigning the first client as default client and to remove the default client service.')
85+
->end()
8286
->arrayNode('main_alias')
8387
->addDefaultsIfNotSet()
8488
->info('Configure which service the main alias point to.')

src/DependencyInjection/HttplugExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public function load(array $configs, ContainerBuilder $container): void
112112
$container->removeAlias(ClientInterface::class);
113113
}
114114

115+
if (!$config['default_client']) {
116+
$container->removeAlias('httplug.client');
117+
$container->removeAlias('httplug.client.default');
118+
$container->removeDefinition('httplug.client.default');
119+
}
120+
115121
if ($this->useVcrPlugin) {
116122
if (!\class_exists(RecordPlugin::class)) {
117123
throw new InvalidConfigurationException('You need to require the VCR plugin to be able to use it: "composer require --dev php-http/vcr-plugin".');
@@ -139,6 +145,10 @@ private function configureClients(ContainerBuilder $container, array $config): v
139145
$clients[] = $name;
140146
}
141147

148+
if (!$config['default_client']) {
149+
return;
150+
}
151+
142152
// If we have clients configured
143153
if (null !== $first) {
144154
// If we do not have a client named 'default'

0 commit comments

Comments
 (0)