|
2 | 2 |
|
3 | 3 | namespace Http\HttplugBundle\DependencyInjection;
|
4 | 4 |
|
| 5 | +use Http\Client\Common\FlexibleHttpClient; |
| 6 | +use Http\Client\Common\HttpMethodsClient; |
5 | 7 | use Http\Client\Common\Plugin\AuthenticationPlugin;
|
6 | 8 | use Http\Client\Common\PluginClient;
|
7 | 9 | use Http\HttplugBundle\ClientFactory\DummyClient;
|
@@ -77,19 +79,7 @@ private function configureClients(ContainerBuilder $container, array $config)
|
77 | 79 | array_unshift($arguments['plugins'], 'httplug.collector.history_plugin');
|
78 | 80 | }
|
79 | 81 |
|
80 |
| - $def = $container->register('httplug.client.'.$name, DummyClient::class); |
81 |
| - |
82 |
| - if (empty($arguments['plugins'])) { |
83 |
| - $def->setFactory([new Reference($arguments['factory']), 'createClient']) |
84 |
| - ->addArgument($arguments['config']); |
85 |
| - } else { |
86 |
| - $def->setFactory('Http\HttplugBundle\ClientFactory\PluginClientFactory::createPluginClient') |
87 |
| - ->addArgument(array_map(function ($id) { |
88 |
| - return new Reference($id); |
89 |
| - }, $arguments['plugins'])) |
90 |
| - ->addArgument(new Reference($arguments['factory'])) |
91 |
| - ->addArgument($arguments['config']); |
92 |
| - } |
| 82 | + $this->configureClient($container, $name, $arguments); |
93 | 83 | }
|
94 | 84 |
|
95 | 85 | // If we have clients configured
|
@@ -206,4 +196,51 @@ private function configureAuthentication(ContainerBuilder $container, array $con
|
206 | 196 | ->addArgument(new Reference($authServiceKey));
|
207 | 197 | }
|
208 | 198 | }
|
| 199 | + |
| 200 | + /** |
| 201 | + * @param ContainerBuilder $container |
| 202 | + * @param string $name |
| 203 | + * @param array $arguments |
| 204 | + */ |
| 205 | + private function configureClient(ContainerBuilder $container, $name, array $arguments) |
| 206 | + { |
| 207 | + $serviceId = 'httplug.client.'.$name; |
| 208 | + $def = $container->register($serviceId, DummyClient::class); |
| 209 | + |
| 210 | + if (empty($arguments['plugins'])) { |
| 211 | + $def->setFactory([new Reference($arguments['factory']), 'createClient']) |
| 212 | + ->addArgument($arguments['config']); |
| 213 | + } else { |
| 214 | + $def->setFactory('Http\HttplugBundle\ClientFactory\PluginClientFactory::createPluginClient') |
| 215 | + ->addArgument( |
| 216 | + array_map( |
| 217 | + function ($id) { |
| 218 | + return new Reference($id); |
| 219 | + }, |
| 220 | + $arguments['plugins'] |
| 221 | + ) |
| 222 | + ) |
| 223 | + ->addArgument(new Reference($arguments['factory'])) |
| 224 | + ->addArgument($arguments['config']); |
| 225 | + } |
| 226 | + |
| 227 | + |
| 228 | + /* |
| 229 | + * Decorate the client with clients from client-common |
| 230 | + */ |
| 231 | + |
| 232 | + if ($arguments['flexible_client']) { |
| 233 | + $container->register($serviceId.'.flexible', FlexibleHttpClient::class) |
| 234 | + ->addArgument(new Reference($serviceId.'.flexible.inner')) |
| 235 | + ->setPublic(false) |
| 236 | + ->setDecoratedService($serviceId); |
| 237 | + } |
| 238 | + |
| 239 | + if ($arguments['http_methods_client']) { |
| 240 | + $container->register($serviceId.'.http_methods', HttpMethodsClient::class) |
| 241 | + ->setArguments([new Reference($serviceId.'.http_methods.inner'), new Reference('httplug.message_factory')]) |
| 242 | + ->setPublic(false) |
| 243 | + ->setDecoratedService($serviceId); |
| 244 | + } |
| 245 | + } |
209 | 246 | }
|
0 commit comments