|
3 | 3 | namespace Http\HttplugBundle\DependencyInjection;
|
4 | 4 |
|
5 | 5 | use Http\Client\Common\BatchClient;
|
| 6 | +use Http\Client\Common\BatchClientInterface; |
6 | 7 | use Http\Client\Common\FlexibleHttpClient;
|
7 | 8 | use Http\Client\Common\HttpMethodsClient;
|
| 9 | +use Http\Client\Common\HttpMethodsClientInterface; |
8 | 10 | use Http\Client\Common\Plugin\AuthenticationPlugin;
|
9 | 11 | use Http\Client\Common\PluginClient;
|
10 | 12 | use Http\Client\Common\PluginClientFactory;
|
@@ -111,9 +113,30 @@ private function configureClients(ContainerBuilder $container, array $config)
|
111 | 113 | // If we have clients configured
|
112 | 114 | if (null !== $first) {
|
113 | 115 | // If we do not have a client named 'default'
|
114 |
| - if (!isset($config['clients']['default'])) { |
| 116 | + if (!array_key_exists('default', $config['clients'])) { |
| 117 | + $serviceId = 'httplug.client.'.$first; |
115 | 118 | // Alias the first client to httplug.client.default
|
116 |
| - $container->setAlias('httplug.client.default', 'httplug.client.'.$first); |
| 119 | + $container->setAlias('httplug.client.default', $serviceId); |
| 120 | + $default = $first; |
| 121 | + } else { |
| 122 | + $default = 'default'; |
| 123 | + } |
| 124 | + |
| 125 | + // Autowiring alias for special clients, if they are enabled on the default client |
| 126 | + if ($config['clients'][$default]['flexible_client']) { |
| 127 | + $container->setAlias(FlexibleHttpClient::class, $serviceId.'.flexible'); |
| 128 | + } |
| 129 | + if ($config['clients'][$default]['http_methods_client']) { |
| 130 | + if (\interface_exists(HttpMethodsClientInterface::class)) { |
| 131 | + // support for client-common 1.9 |
| 132 | + $container->setAlias(HttpMethodsClientInterface::class, $serviceId.'.http_methods'); |
| 133 | + } |
| 134 | + } |
| 135 | + if ($config['clients'][$default]['batch_client']) { |
| 136 | + if (\interface_exists(BatchClientInterface::class)) { |
| 137 | + // support for client-common 1.9 |
| 138 | + $container->setAlias(BatchClientInterface::class, $serviceId.'.batch_client'); |
| 139 | + } |
117 | 140 | }
|
118 | 141 | }
|
119 | 142 | }
|
|
0 commit comments