diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6796e..64aa135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 2 +# 2.2.0 + +- Added `default_client` configuration option to disable assigning the first client as default client and to remove the default client service. + # 2.1.0 - 2024-11-24 - Added [PluginConfigurator](https://docs.php-http.org/en/latest/integrations/symfony-bundle.html#configure-a-custom-plugin) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f9d0fdb..c5a19a3 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -79,6 +79,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->defaultTrue() ->info('Set to false to not autowire ClientInterface and HttpAsyncClient.') ->end() + ->booleanNode('default_client') + ->defaultTrue() + ->info('Set to false to disable assigning the first client as default client and to remove the default client service.') + ->end() ->arrayNode('main_alias') ->addDefaultsIfNotSet() ->info('Configure which service the main alias point to.') diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index d8c913c..9176890 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -112,6 +112,12 @@ public function load(array $configs, ContainerBuilder $container): void $container->removeAlias(ClientInterface::class); } + if (!$config['default_client']) { + $container->removeAlias('httplug.client'); + $container->removeAlias('httplug.client.default'); + $container->removeDefinition('httplug.client.default'); + } + if ($this->useVcrPlugin) { if (!\class_exists(RecordPlugin::class)) { 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 $clients[] = $name; } + if (!$config['default_client']) { + return; + } + // If we have clients configured if (null !== $first) { // If we do not have a client named 'default'