Skip to content

Commit deb4eb3

Browse files
committed
fix after feedback
1 parent a7cafb4 commit deb4eb3

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

DependencyInjection/HttplugExtension.php

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function load(array $configs, ContainerBuilder $container)
5555
}
5656

5757
// Configure toolbar
58-
if ($config['profiling']['enabled']) {
58+
if ($this->isConfigEnabled($container, $config['profiling'])) {
5959
$loader->load('data-collector.xml');
6060

6161
if (!empty($config['profiling']['formatter'])) {
@@ -73,7 +73,7 @@ public function load(array $configs, ContainerBuilder $container)
7373
}
7474

7575
$this->configureClients($container, $config);
76-
$this->configureSharedPlugins($container, $config['plugins']); // must be after clients, as the extra_plugins in clients might use plugins as template that will be removed
76+
$this->configureSharedPlugins($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
}
7979

@@ -93,7 +93,7 @@ private function configureClients(ContainerBuilder $container, array $config)
9393
$first = $name;
9494
}
9595

96-
$this->configureClient($container, $name, $arguments, $config['profiling']['enabled']);
96+
$this->configureClient($container, $name, $arguments, $this->isConfigEnabled($container, $config['profiling']));
9797
}
9898

9999
// If we have clients configured
@@ -120,7 +120,7 @@ private function configureSharedPlugins(ContainerBuilder $container, array $conf
120120
foreach ($config as $name => $pluginConfig) {
121121
$pluginId = 'httplug.plugin.'.$name;
122122

123-
if ($pluginConfig['enabled']) {
123+
if ($this->isConfigEnabled($container, $pluginConfig)) {
124124
$def = $container->getDefinition($pluginId);
125125
$this->configurePluginByName($name, $def, $pluginConfig, $container, $pluginId);
126126
} else {
@@ -230,54 +230,49 @@ private function configureAuthentication(ContainerBuilder $container, array $con
230230

231231
/**
232232
* @param ContainerBuilder $container
233-
* @param string $name
233+
* @param string $clientName
234234
* @param array $arguments
235235
* @param bool $profiling
236236
*/
237-
private function configureClient(ContainerBuilder $container, $name, array $arguments, $profiling)
237+
private function configureClient(ContainerBuilder $container, $clientName, array $arguments, $profiling)
238238
{
239-
$serviceId = 'httplug.client.'.$name;
239+
$serviceId = 'httplug.client.'.$clientName;
240240

241-
$pluginClientOptions = [];
241+
$plugins = [];
242+
foreach ($arguments['plugins'] as $plugin) {
243+
list($pluginName, $pluginConfig) = each($plugin);
244+
if ('reference' === $pluginName) {
245+
$plugins[] = $pluginConfig['id'];
246+
} elseif ('authentication' === $pluginName) {
247+
// TODO handle custom authentication
248+
} else {
249+
$pluginServiceId = $serviceId.'.plugin.'.$pluginName;
250+
$def = clone $container->getDefinition('httplug.plugin'.'.'.$pluginName);
251+
$def->setAbstract(false);
252+
$this->configurePluginByName($pluginName, $def, $pluginConfig, $container, $pluginServiceId);
253+
$container->setDefinition($pluginServiceId, $def);
254+
$plugins[] = $pluginServiceId;
255+
}
256+
}
242257

258+
$pluginClientOptions = [];
243259
if ($profiling) {
260+
// Add the stopwatch plugin
244261
if (!in_array('httplug.plugin.stopwatch', $arguments['plugins'])) {
245-
// Add the stopwatch plugin
246-
array_unshift($arguments['plugins'], [
247-
'reference' => [
248-
'id' => 'httplug.plugin.stopwatch',
249-
],
250-
]);
262+
array_unshift($plugins, 'httplug.plugin.stopwatch');
251263
}
252264

253265
// Tell the plugin journal what plugins we used
254266
$container
255267
->getDefinition('httplug.collector.plugin_journal')
256-
->addMethodCall('setPlugins', [$name, $arguments['plugins']])
268+
->addMethodCall('setPlugins', [$clientName, $plugins])
257269
;
258270

259271
$debugPluginServiceId = $this->registerDebugPlugin($container, $serviceId);
260272

261273
$pluginClientOptions['debug_plugins'] = [new Reference($debugPluginServiceId)];
262274
}
263275

264-
$plugins = [];
265-
foreach ($arguments['plugins'] as $plugin) {
266-
list($name, $pluginConfig) = each($plugin);
267-
if ('reference' === $name) {
268-
$plugins[] = $pluginConfig['id'];
269-
} elseif ('authentication' === $name) {
270-
// TODO handle custom authentication
271-
} else {
272-
$pluginServiceId = $serviceId.'.plugin.'.$name;
273-
$def = clone $container->getDefinition('httplug.plugin'.'.'.$name);
274-
$def->setAbstract(false);
275-
$this->configurePluginByName($name, $def, $pluginConfig, $container, $pluginServiceId);
276-
$container->setDefinition($pluginServiceId, $def);
277-
$plugins[] = $pluginServiceId;
278-
}
279-
}
280-
281276
$container
282277
->register($serviceId, DummyClient::class)
283278
->setFactory([PluginClientFactory::class, 'createPluginClient'])
@@ -360,7 +355,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
360355
$container,
361356
'auto_discovered_client',
362357
[HttpClientDiscovery::class, 'find'],
363-
$config['profiling']['enabled']
358+
$this->isConfigEnabled($container, $config['profiling'])
364359
);
365360
}
366361

@@ -375,7 +370,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
375370
$container,
376371
'auto_discovered_async',
377372
[HttpAsyncClientDiscovery::class, 'find'],
378-
$config['profiling']['enabled']
373+
$this->isConfigEnabled($container, $config['profiling'])
379374
);
380375
}
381376

0 commit comments

Comments
 (0)