77use Http \Client \Common \HttpMethodsClient ;
88use Http \Client \Common \Plugin \AuthenticationPlugin ;
99use Http \Client \Common \PluginClient ;
10- use Http \HttplugBundle \ ClientFactory \PluginClientFactory ;
11- use Http \HttplugBundle \ Collector \ ProfilePlugin ;
10+ use Http \Client \ Common \PluginClientFactory ;
11+ use Http \Client \ HttpClient ;
1212use Http \Message \Authentication \BasicAuth ;
1313use Http \Message \Authentication \Bearer ;
1414use Http \Message \Authentication \Wsse ;
@@ -72,7 +72,7 @@ public function load(array $configs, ContainerBuilder $container)
7272 ;
7373 }
7474
75- $ this ->configureClients ($ container , $ config, $ profilingEnabled );
75+ $ this ->configureClients ($ container , $ config );
7676 $ this ->configurePlugins ($ container , $ config ['plugins ' ]); // must be after clients, as clients.X.plugins might use plugins as templates that will be removed
7777 $ this ->configureAutoDiscoveryClients ($ container , $ config );
7878 }
@@ -82,9 +82,8 @@ public function load(array $configs, ContainerBuilder $container)
8282 *
8383 * @param ContainerBuilder $container
8484 * @param array $config
85- * @param bool $profiling
8685 */
87- private function configureClients (ContainerBuilder $ container , array $ config, $ profiling )
86+ private function configureClients (ContainerBuilder $ container , array $ config )
8887 {
8988 $ first = null ;
9089 $ clients = [];
@@ -95,7 +94,7 @@ private function configureClients(ContainerBuilder $container, array $config, $p
9594 $ first = $ name ;
9695 }
9796
98- $ this ->configureClient ($ container , $ name , $ arguments, $ this -> isConfigEnabled ( $ container , $ config [ ' profiling ' ]) );
97+ $ this ->configureClient ($ container , $ name , $ arguments );
9998 $ clients [] = $ name ;
10099 }
101100
@@ -266,9 +265,8 @@ private function configureAuthentication(ContainerBuilder $container, array $con
266265 * @param ContainerBuilder $container
267266 * @param string $clientName
268267 * @param array $arguments
269- * @param bool $profiling
270268 */
271- private function configureClient (ContainerBuilder $ container , $ clientName , array $ arguments, $ profiling )
269+ private function configureClient (ContainerBuilder $ container , $ clientName , array $ arguments )
272270 {
273271 $ serviceId = 'httplug.client. ' .$ clientName ;
274272
@@ -285,23 +283,17 @@ private function configureClient(ContainerBuilder $container, $clientName, array
285283 }
286284 }
287285
288- $ pluginClientOptions = [];
289- if ($ profiling ) {
290- //Decorate each plugin with a ProfilePlugin instance.
291- $ plugins = array_map (function ($ pluginServiceId ) use ($ container ) {
292- $ this ->decoratePluginWithProfilePlugin ($ container , $ pluginServiceId );
293-
294- return $ pluginServiceId .'.debug ' ;
295- }, $ plugins );
296-
297- // To profile the requests, add a StackPlugin as first plugin in the chain.
298- $ stackPluginId = $ this ->configureStackPlugin ($ container , $ clientName , $ serviceId );
299- array_unshift ($ plugins , $ stackPluginId );
300- }
286+ $ container
287+ ->register ($ serviceId .'.client ' , HttpClient::class)
288+ ->setFactory ([new Reference ($ arguments ['factory ' ]), 'createClient ' ])
289+ ->addArgument ($ arguments ['config ' ])
290+ ->setPublic (false )
291+ ;
301292
302293 $ container
303294 ->register ($ serviceId , PluginClient::class)
304- ->setFactory ([PluginClientFactory::class, 'createPluginClient ' ])
295+ ->setFactory ([new Reference (PluginClientFactory::class), 'createClient ' ])
296+ ->addArgument (new Reference ($ serviceId .'.client ' ))
305297 ->addArgument (
306298 array_map (
307299 function ($ id ) {
@@ -310,9 +302,9 @@ function ($id) {
310302 $ plugins
311303 )
312304 )
313- ->addArgument (new Reference ( $ arguments [ ' factory ' ]))
314- -> addArgument ( $ arguments [ ' config ' ])
315- -> addArgument ( $ pluginClientOptions )
305+ ->addArgument ([
306+ ' client_name ' => $ clientName ,
307+ ] )
316308 ;
317309
318310 /*
@@ -432,44 +424,4 @@ private function configurePlugin(ContainerBuilder $container, $serviceId, $plugi
432424
433425 return $ pluginServiceId ;
434426 }
435-
436- /**
437- * Decorate the plugin service with a ProfilePlugin service.
438- *
439- * @param ContainerBuilder $container
440- * @param string $pluginServiceId
441- */
442- private function decoratePluginWithProfilePlugin (ContainerBuilder $ container , $ pluginServiceId )
443- {
444- $ container ->register ($ pluginServiceId .'.debug ' , ProfilePlugin::class)
445- ->setArguments ([
446- new Reference ($ pluginServiceId ),
447- new Reference ('httplug.collector.collector ' ),
448- new Reference ('httplug.collector.formatter ' ),
449- ])
450- ->setPublic (false );
451- }
452-
453- /**
454- * Configure a StackPlugin for a client.
455- *
456- * @param ContainerBuilder $container
457- * @param string $clientName Client name to display in the profiler.
458- * @param string $serviceId Client service id. Used as base for the StackPlugin service id.
459- *
460- * @return string configured StackPlugin service id
461- */
462- private function configureStackPlugin (ContainerBuilder $ container , $ clientName , $ serviceId )
463- {
464- $ pluginServiceId = $ serviceId .'.plugin.stack ' ;
465-
466- $ definition = class_exists (ChildDefinition::class)
467- ? new ChildDefinition ('httplug.plugin.stack ' )
468- : new DefinitionDecorator ('httplug.plugin.stack ' );
469-
470- $ definition ->addArgument ($ clientName );
471- $ container ->setDefinition ($ pluginServiceId , $ definition );
472-
473- return $ pluginServiceId ;
474- }
475427}
0 commit comments