Skip to content

Commit 39710ca

Browse files
committed
support autowire convenience clients
this only happens for the "default" client: the first configured client or the one called default.
1 parent f718e56 commit 39710ca

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CHANGELOG.md

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

55
## 1.15.0 [unreleased]
66

7+
### Added
8+
9+
- Autowiring support for FlexibleClient, HttpMethodsClient and BatchClient if
10+
they are enabled on the default/first client.
11+
712
### Changed
813

914
- Removed `twig/twig` dependency

DependencyInjection/HttplugExtension.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,24 @@ private function configureClients(ContainerBuilder $container, array $config)
111111
// If we have clients configured
112112
if (null !== $first) {
113113
// If we do not have a client named 'default'
114-
if (!isset($config['clients']['default'])) {
114+
if (!array_key_exists('default', $config['clients'])) {
115+
$serviceId = 'httplug.client.' . $first;
115116
// Alias the first client to httplug.client.default
116-
$container->setAlias('httplug.client.default', 'httplug.client.'.$first);
117+
$container->setAlias('httplug.client.default', $serviceId);
118+
$default = $first;
119+
} else {
120+
$default = 'default';
121+
}
122+
123+
// Autowiring alias for special clients, if they are enabled on the default client
124+
if ($config['clients'][$default]['flexible_client']) {
125+
$container->setAlias(FlexibleHttpClient::class, $serviceId . '.flexible');
126+
}
127+
if ($config['clients'][$default]['http_methods_client']) {
128+
$container->setAlias(HttpMethodsClient::class, $serviceId . '.http_methods');
129+
}
130+
if ($config['clients'][$default]['batch_client']) {
131+
$container->setAlias(BatchClient::class, $serviceId . '.batch_client');
117132
}
118133
}
119134
}

0 commit comments

Comments
 (0)