@@ -39,10 +39,10 @@ public function load(array $configs, ContainerBuilder $container)
39
39
$ loader ->load ('services.xml ' );
40
40
$ loader ->load ('plugins.xml ' );
41
41
42
- $ enabled = is_bool ($ config ['toolbar ' ]['enabled ' ]) ? $ config ['toolbar ' ]['enabled ' ] : $ container ->hasParameter ('kernel.debug ' ) && $ container ->getParameter ('kernel.debug ' );
43
- if ($ enabled ) {
42
+ $ toolbar = is_bool ($ config ['toolbar ' ]['enabled ' ]) ? $ config ['toolbar ' ]['enabled ' ] : $ container ->hasParameter ('kernel.debug ' ) && $ container ->getParameter ('kernel.debug ' );
43
+
44
+ if ($ toolbar ) {
44
45
$ loader ->load ('data-collector.xml ' );
45
- $ config ['_inject_collector_plugin ' ] = true ;
46
46
47
47
if (!empty ($ config ['toolbar ' ]['formatter ' ])) {
48
48
// Add custom formatter
@@ -66,17 +66,18 @@ public function load(array $configs, ContainerBuilder $container)
66
66
}
67
67
68
68
$ this ->configurePlugins ($ container , $ config ['plugins ' ]);
69
- $ this ->configureClients ($ container , $ config );
70
- $ this ->configureAutoDiscoveryClients ($ container , $ config );
69
+ $ this ->configureClients ($ container , $ config, $ toolbar );
70
+ $ this ->configureAutoDiscoveryClients ($ container , $ config, $ toolbar );
71
71
}
72
72
73
73
/**
74
74
* Configure client services.
75
75
*
76
76
* @param ContainerBuilder $container
77
77
* @param array $config
78
+ * @param bool $enableCollector
78
79
*/
79
- private function configureClients (ContainerBuilder $ container , array $ config )
80
+ private function configureClients (ContainerBuilder $ container , array $ config, $ enableCollector )
80
81
{
81
82
// If we have a client named 'default'
82
83
$ first = isset ($ config ['clients ' ]['default ' ]) ? 'default ' : null ;
@@ -87,7 +88,7 @@ private function configureClients(ContainerBuilder $container, array $config)
87
88
$ first = $ name ;
88
89
}
89
90
90
- $ this ->configureClient ($ container , $ name , $ arguments , $ config [ ' _inject_collector_plugin ' ] );
91
+ $ this ->configureClient ($ container , $ name , $ arguments , $ enableCollector );
91
92
}
92
93
93
94
// If we have clients configured
@@ -96,7 +97,7 @@ private function configureClients(ContainerBuilder $container, array $config)
96
97
// Alias the first client to httplug.client.default
97
98
$ container ->setAlias ('httplug.client.default ' , 'httplug.client. ' .$ first );
98
99
}
99
- } elseif (isset ( $ config [ ' _inject_collector_plugin ' ]) ) {
100
+ } elseif ($ enableCollector ) {
100
101
$ serviceIdDebugPlugin = $ this ->registerDebugPlugin ($ container , 'default ' );
101
102
// No client was configured. Make sure to configure the auto discovery client with the PluginClient.
102
103
$ container ->register ('httplug.client ' , PluginClient::class)
@@ -218,14 +219,13 @@ private function configureClient(ContainerBuilder $container, $name, array $argu
218
219
$ serviceId = 'httplug.client. ' .$ name ;
219
220
$ def = $ container ->register ($ serviceId , DummyClient::class);
220
221
221
- // If there is no plugins nor should we use the data collector
222
+ // If there are no plugins nor should we use the data collector
222
223
if (empty ($ arguments ['plugins ' ]) && !$ enableCollector ) {
223
224
$ def ->setFactory ([new Reference ($ arguments ['factory ' ]), 'createClient ' ])
224
225
->addArgument ($ arguments ['config ' ]);
225
226
} else {
226
- $ serviceIdDebugPlugin = $ this ->registerDebugPlugin ($ container , $ name );
227
-
228
- $ def ->setFactory ('Http\HttplugBundle\ClientFactory\PluginClientFactory::createPluginClient ' )
227
+ $ def
228
+ ->setFactory ('Http\HttplugBundle\ClientFactory\PluginClientFactory::createPluginClient ' )
229
229
->addArgument (
230
230
array_map (
231
231
function ($ id ) {
@@ -236,13 +236,17 @@ function ($id) {
236
236
)
237
237
->addArgument (new Reference ($ arguments ['factory ' ]))
238
238
->addArgument ($ arguments ['config ' ])
239
- -> addArgument ([ ' debug_plugins ' => [ new Reference ( $ serviceIdDebugPlugin )]]) ;
239
+ ;
240
240
241
- // tell the plugin journal what plugins we used
242
- $ container ->getDefinition ('httplug.collector.plugin_journal ' )
243
- ->addMethodCall ('setPlugins ' , [$ name , $ arguments ['plugins ' ]]);
244
- }
241
+ if ($ enableCollector ) {
242
+ $ serviceIdDebugPlugin = $ this ->registerDebugPlugin ($ container , $ name );
243
+ $ def ->addArgument (['debug_plugins ' => [new Reference ($ serviceIdDebugPlugin )]]);
245
244
245
+ // tell the plugin journal what plugins we used
246
+ $ container ->getDefinition ('httplug.collector.plugin_journal ' )
247
+ ->addMethodCall ('setPlugins ' , [$ name , $ arguments ['plugins ' ]]);
248
+ }
249
+ }
246
250
247
251
/*
248
252
* Decorate the client with clients from client-common
@@ -287,15 +291,17 @@ private function registerDebugPlugin(ContainerBuilder $container, $name)
287
291
*
288
292
* @param ContainerBuilder $container
289
293
* @param array $config
294
+ * @param bool $enableCollector
290
295
*/
291
- private function configureAutoDiscoveryClients (ContainerBuilder $ container , array $ config )
296
+ private function configureAutoDiscoveryClients (ContainerBuilder $ container , array $ config, $ enableCollector )
292
297
{
293
298
$ httpClient = $ config ['discovery ' ]['client ' ];
294
299
if ($ httpClient === 'auto ' ) {
295
300
$ httpClient = $ this ->registerAutoDiscoverableClientWithDebugPlugin (
296
301
$ container ,
297
302
'client ' ,
298
- [HttpClientDiscovery::class, 'find ' ]
303
+ [HttpClientDiscovery::class, 'find ' ],
304
+ $ enableCollector
299
305
);
300
306
} elseif ($ httpClient ) {
301
307
$ httpClient = new Reference ($ httpClient );
@@ -306,8 +312,9 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
306
312
$ asyncHttpClient = $ this ->registerAutoDiscoverableClientWithDebugPlugin (
307
313
$ container ,
308
314
'async_client ' ,
309
- [HttpAsyncClientDiscovery::class, 'find ' ]
310
- );
315
+ [HttpAsyncClientDiscovery::class, 'find ' ],
316
+ $ enableCollector
317
+ );
311
318
} elseif ($ asyncHttpClient ) {
312
319
$ asyncHttpClient = new Reference ($ httpClient );
313
320
}
@@ -321,21 +328,27 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
321
328
* @param ContainerBuilder $container
322
329
* @param string $name
323
330
* @param callable $factory
331
+ * @param bool $enableCollector
324
332
*
325
333
* @return Reference
326
334
*/
327
- private function registerAutoDiscoverableClientWithDebugPlugin (ContainerBuilder $ container , $ name , $ factory )
335
+ private function registerAutoDiscoverableClientWithDebugPlugin (ContainerBuilder $ container , $ name , $ factory, $ enableCollector )
328
336
{
329
337
$ definition = $ container ->register ('httplug.auto_discovery_ ' .$ name .'.pure ' , DummyClient::class);
330
338
$ definition ->setPublic (false );
331
339
$ definition ->setFactory ($ factory );
332
340
333
- $ serviceIdDebugPlugin = $ this -> registerDebugPlugin ( $ container, ' auto_discovery_ ' . $ name );
334
- $ container ->register ('httplug.auto_discovery_ ' .$ name .'.plugin ' , PluginClient::class)
341
+ $ pluginDefinition = $ container
342
+ ->register ('httplug.auto_discovery_ ' .$ name .'.plugin ' , PluginClient::class)
335
343
->setPublic (false )
336
344
->addArgument (new Reference ('httplug.auto_discovery_ ' .$ name .'.pure ' ))
337
345
->addArgument ([])
338
- ->addArgument (['debug_plugins ' => [new Reference ($ serviceIdDebugPlugin )]]);
346
+ ;
347
+
348
+ if ($ enableCollector ) {
349
+ $ serviceIdDebugPlugin = $ this ->registerDebugPlugin ($ container , 'auto_discovery_ ' .$ name );
350
+ $ pluginDefinition ->addArgument (['debug_plugins ' => [new Reference ($ serviceIdDebugPlugin )]]);
351
+ }
339
352
340
353
return new Reference ('httplug.auto_discovery_ ' .$ name .'.plugin ' );
341
354
}
0 commit comments