Skip to content

Commit 17d6307

Browse files
committed
Rename toolbar config to profiling
1 parent d42d86c commit 17d6307

File tree

10 files changed

+138
-87
lines changed

10 files changed

+138
-87
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
### Deprecated
1616

1717
- `auto` value in `toolbar.enabled` config
18+
- `toolbar` config, use `profiling` instead
1819

1920

2021
## 1.2.2 - 2016-07-19

DependencyInjection/Configuration.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ public function getConfigTreeBuilder()
6969
return $v;
7070
})
7171
->end()
72+
->beforeNormalization()
73+
->ifTrue(function ($v) {
74+
return is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']);
75+
})
76+
->then(function ($v) {
77+
if (array_key_exists('profiling', $v)) {
78+
throw new InvalidConfigurationException('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".');
79+
}
80+
81+
@trigger_error('"httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use "httplug.profiling" instead.', E_USER_DEPRECATED);
82+
83+
if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) {
84+
@trigger_error('"auto" value in "httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use a boolean value instead.', E_USER_DEPRECATED);
85+
$v['toolbar']['enabled'] = $this->debug;
86+
}
87+
88+
$v['profiling'] = $v['toolbar'];
89+
90+
unset($v['toolbar']);
91+
92+
return $v;
93+
})
94+
->end()
7295
->children()
7396
->arrayNode('main_alias')
7497
->addDefaultsIfNotSet()
@@ -90,17 +113,14 @@ public function getConfigTreeBuilder()
90113
->scalarNode('stream_factory')->defaultNull()->end()
91114
->end()
92115
->end()
93-
->arrayNode('toolbar')
116+
->arrayNode('profiling')
94117
->addDefaultsIfNotSet()
118+
->treatFalseLike(['enabled' => false])
119+
->treatTrueLike(['enabled' => true])
120+
->treatNullLike(['enabled' => $this->debug])
95121
->info('Extend the debug profiler with information about requests.')
96122
->children()
97-
->booleanNode('enabled') // @deprecated value auto in 1.3.0
98-
->beforeNormalization()
99-
->ifString()
100-
->then(function ($v) {
101-
return 'auto' === $v ? $this->debug : $v;
102-
})
103-
->end()
123+
->booleanNode('enabled')
104124
->info('Turn the toolbar on or off. Defaults to kernel debug mode.')
105125
->defaultValue($this->debug)
106126
->end()

DependencyInjection/HttplugExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ public function load(array $configs, ContainerBuilder $container)
5353
}
5454

5555
// Configure toolbar
56-
if ($config['toolbar']['enabled']) {
56+
if ($config['profiling']['enabled']) {
5757
$loader->load('data-collector.xml');
5858

59-
if (!empty($config['toolbar']['formatter'])) {
59+
if (!empty($config['profiling']['formatter'])) {
6060
// Add custom formatter
6161
$container
6262
->getDefinition('httplug.collector.debug_collector')
63-
->replaceArgument(0, new Reference($config['toolbar']['formatter']))
63+
->replaceArgument(0, new Reference($config['profiling']['formatter']))
6464
;
6565
}
6666

6767
$container
6868
->getDefinition('httplug.formatter.full_http_message')
69-
->addArgument($config['toolbar']['captured_body_length'])
69+
->addArgument($config['profiling']['captured_body_length'])
7070
;
7171
}
7272

@@ -91,7 +91,7 @@ private function configureClients(ContainerBuilder $container, array $config)
9191
$first = $name;
9292
}
9393

94-
$this->configureClient($container, $name, $arguments, $config['toolbar']['enabled']);
94+
$this->configureClient($container, $name, $arguments, $config['profiling']['enabled']);
9595
}
9696

9797
// If we have clients configured
@@ -294,7 +294,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
294294
$container,
295295
'auto_discovered_client',
296296
[HttpClientDiscovery::class, 'find'],
297-
$config['toolbar']['enabled']
297+
$config['profiling']['enabled']
298298
);
299299
}
300300

@@ -309,7 +309,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
309309
$container,
310310
'auto_discovered_async',
311311
[HttpAsyncClientDiscovery::class, 'find'],
312-
$config['toolbar']['enabled']
312+
$config['profiling']['enabled']
313313
);
314314
}
315315

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
httplug:
2+
profiling: ~
3+
toolbar:
4+
enabled: auto
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
httplug:
2+
toolbar:
3+
enabled: true
4+
formatter: null
5+
captured_body_length: 0

Tests/Resources/Fixtures/config/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'uri_factory' => 'Http\Message\UriFactory\GuzzleUriFactory',
1414
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
1515
],
16-
'toolbar' => [
16+
'profiling' => [
1717
'enabled' => true,
1818
'formatter' => 'my_toolbar_formatter',
1919
'captured_body_length' => 0,

Tests/Resources/Fixtures/config/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<uri-factory>Http\Message\UriFactory\GuzzleUriFactory</uri-factory>
1515
<stream-factory>Http\Message\StreamFactory\GuzzleStreamFactory</stream-factory>
1616
</classes>
17-
<toolbar enabled="true" formatter="my_toolbar_formatter" captured_body_length="0"/>
17+
<profiling enabled="true" formatter="my_toolbar_formatter" captured_body_length="0"/>
1818
<plugins>
1919
<authentication>
2020
<my_basic type="basic" username="foo" password="bar"/>

Tests/Resources/Fixtures/config/full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ httplug:
99
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
1010
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
1111
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
12-
toolbar:
12+
profiling:
1313
enabled: true
1414
formatter: my_toolbar_formatter
1515
captured_body_length: 0

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,69 @@
1111
*/
1212
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
1313
{
14-
private $debug = true;
14+
private $emptyConfig = [
15+
'main_alias' => [
16+
'client' => 'httplug.client.default',
17+
'message_factory' => 'httplug.message_factory.default',
18+
'uri_factory' => 'httplug.uri_factory.default',
19+
'stream_factory' => 'httplug.stream_factory.default',
20+
],
21+
'classes' => [
22+
'client' => null,
23+
'message_factory' => null,
24+
'uri_factory' => null,
25+
'stream_factory' => null,
26+
],
27+
'clients' => [],
28+
'profiling' => [
29+
'enabled' => true,
30+
'formatter' => null,
31+
'captured_body_length' => 0,
32+
],
33+
'plugins' => [
34+
'authentication' => [],
35+
'cache' => [
36+
'enabled' => false,
37+
'stream_factory' => 'httplug.stream_factory',
38+
'config' => [
39+
'default_ttl' => null,
40+
'respect_cache_headers' => true,
41+
],
42+
],
43+
'cookie' => [
44+
'enabled' => false,
45+
],
46+
'decoder' => [
47+
'enabled' => true,
48+
'use_content_encoding' => true,
49+
],
50+
'history' => [
51+
'enabled' => false,
52+
],
53+
'logger' => [
54+
'enabled' => true,
55+
'logger' => 'logger',
56+
'formatter' => null,
57+
],
58+
'redirect' => [
59+
'enabled' => true,
60+
'preserve_header' => true,
61+
'use_default_for_multiple' => true,
62+
],
63+
'retry' => [
64+
'enabled' => true,
65+
'retry' => 1,
66+
],
67+
'stopwatch' => [
68+
'enabled' => true,
69+
'stopwatch' => 'debug.stopwatch',
70+
],
71+
],
72+
'discovery' => [
73+
'client' => 'auto',
74+
'async_client' => null,
75+
],
76+
];
1577

1678
protected function getContainerExtension()
1779
{
@@ -20,86 +82,21 @@ protected function getContainerExtension()
2082

2183
protected function getConfiguration()
2284
{
23-
return new Configuration($this->debug);
85+
return new Configuration(true);
2486
}
2587

2688
public function testEmptyConfiguration()
2789
{
28-
$expectedConfiguration = [
29-
'main_alias' => [
30-
'client' => 'httplug.client.default',
31-
'message_factory' => 'httplug.message_factory.default',
32-
'uri_factory' => 'httplug.uri_factory.default',
33-
'stream_factory' => 'httplug.stream_factory.default',
34-
],
35-
'classes' => [
36-
'client' => null,
37-
'message_factory' => null,
38-
'uri_factory' => null,
39-
'stream_factory' => null,
40-
],
41-
'clients' => [],
42-
'toolbar' => [
43-
'enabled' => true,
44-
'formatter' => null,
45-
'captured_body_length' => 0,
46-
],
47-
'plugins' => [
48-
'authentication' => [],
49-
'cache' => [
50-
'enabled' => false,
51-
'stream_factory' => 'httplug.stream_factory',
52-
'config' => [
53-
'default_ttl' => null,
54-
'respect_cache_headers' => true,
55-
],
56-
],
57-
'cookie' => [
58-
'enabled' => false,
59-
],
60-
'decoder' => [
61-
'enabled' => true,
62-
'use_content_encoding' => true,
63-
],
64-
'history' => [
65-
'enabled' => false,
66-
],
67-
'logger' => [
68-
'enabled' => true,
69-
'logger' => 'logger',
70-
'formatter' => null,
71-
],
72-
'redirect' => [
73-
'enabled' => true,
74-
'preserve_header' => true,
75-
'use_default_for_multiple' => true,
76-
],
77-
'retry' => [
78-
'enabled' => true,
79-
'retry' => 1,
80-
],
81-
'stopwatch' => [
82-
'enabled' => true,
83-
'stopwatch' => 'debug.stopwatch',
84-
],
85-
],
86-
'discovery' => [
87-
'client' => 'auto',
88-
'async_client' => null,
89-
],
90-
];
91-
9290
$formats = array_map(function ($path) {
9391
return __DIR__.'/../../Resources/Fixtures/'.$path;
9492
}, [
9593
'config/empty.yml',
9694
'config/empty.xml',
9795
'config/empty.php',
98-
'config/toolbar_auto.yml',
9996
]);
10097

10198
foreach ($formats as $format) {
102-
$this->assertProcessedConfigurationEquals($expectedConfiguration, [$format]);
99+
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
103100
}
104101
}
105102

@@ -119,7 +116,7 @@ public function testSupportsAllConfigFormats()
119116
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
120117
],
121118
'clients' => [],
122-
'toolbar' => [
119+
'profiling' => [
123120
'enabled' => true,
124121
'formatter' => 'my_toolbar_formatter',
125122
'captured_body_length' => 0,
@@ -223,4 +220,28 @@ public function testInvalidAuthentication()
223220
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_auth.yml';
224221
$this->assertProcessedConfigurationEquals([], [$file]);
225222
}
223+
224+
public function testBackwardCompatibility()
225+
{
226+
$formats = array_map(function ($path) {
227+
return __DIR__.'/../../Resources/Fixtures//'.$path;
228+
}, [
229+
'config/bc/toolbar.yml',
230+
'config/bc/toolbar_auto.yml',
231+
]);
232+
233+
foreach ($formats as $format) {
234+
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
235+
}
236+
}
237+
238+
/**
239+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
240+
* @expectedExceptionMessage Can't configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".
241+
*/
242+
public function testProfilingToolbarCollision()
243+
{
244+
$file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml';
245+
$this->assertProcessedConfigurationEquals([], [$file]);
246+
}
226247
}

0 commit comments

Comments
 (0)