Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f678652

Browse files
committed
merged branch jfsimon/issue-8130 (PR #8615)
This PR was merged into the master branch. Discussion ---------- [WebProfilerBundle] make toolbar listener instantiation conditional In the `WebProfilerBundle`, if `intercept_redirects` and `toolbar` options are both `false`, the `toolbar.xml` config file should not be loaded as the listener becomes useless. | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8130 Commits ------- 17cbfc8 [WebProfilerBundle] made toolbar listener instantiation conditional
2 parents aa0cc6b + 17cbfc8 commit f678652

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ public function load(array $configs, ContainerBuilder $container)
4444

4545
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
4646
$loader->load('profiler.xml');
47-
$loader->load('toolbar.xml');
48-
49-
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
47+
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
5048

51-
if (!$config['toolbar']) {
52-
$mode = WebDebugToolbarListener::DISABLED;
53-
} else {
54-
$mode = WebDebugToolbarListener::ENABLED;
49+
if ($config['toolbar'] || $config['intercept_redirects']) {
50+
$loader->load('toolbar.xml');
51+
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
52+
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
5553
}
56-
57-
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
58-
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
5954
}
6055

6156
/**

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,35 @@ public function testDefaultConfig($debug)
8686
$extension = new WebProfilerExtension();
8787
$extension->load(array(array()), $this->container);
8888

89-
$this->assertFalse($this->container->get('web_profiler.debug_toolbar')->isEnabled());
89+
$this->assertFalse($this->container->has('web_profiler.debug_toolbar'));
9090

9191
$this->assertSaneContainer($this->getDumpedContainer());
9292
}
9393

9494
/**
9595
* @dataProvider getDebugModes
9696
*/
97-
public function testToolbarConfig($enabled)
97+
public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listenerInjected, $listenerEnabled)
9898
{
9999
$extension = new WebProfilerExtension();
100-
$extension->load(array(array('toolbar' => $enabled)), $this->container);
100+
$extension->load(array(array('toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects)), $this->container);
101101

102-
$this->assertSame($enabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
102+
$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));
103+
104+
if ($listenerInjected) {
105+
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
106+
}
103107

104108
$this->assertSaneContainer($this->getDumpedContainer());
105109
}
106110

107111
public function getDebugModes()
108112
{
109113
return array(
110-
array(true),
111-
array(false),
114+
array(false, false, false, false),
115+
array(true, false, true, true),
116+
array(false, true, true, false),
117+
array(true, true, true, true),
112118
);
113119
}
114120

0 commit comments

Comments
 (0)