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

Skip to content

Commit a11f901

Browse files
committed
[FrameworkBundle] added a way to disable the profiler
Before: enabled: true # the profiler is enabled and data are collected enabled: false # the profiler is enabled but data are not collected (data can be collected on demand) No way to disable the profiler After: enabled: true # the profiler is enabled and data are collected collect: true enabled: true # the profiler is enabled but data are not collected (data can be collected on demand) collect: false enabled: false # the profiler is disabled
1 parent f675dd8 commit a11f901

File tree

17 files changed

+42
-186
lines changed

17 files changed

+42
-186
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
2.3.0
55
-----
66

7+
* [BC BREAK] added a way to disable the profiler (when disabling the profiler, it is now completely removed)
8+
To get the same "disabled" behavior as before, set `enabled` to `true` and `collect` to `false`
79
* [BC BREAK] the `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass` was moved
810
to `Component\HttpKernel\DependencyInjection\RegisterListenersPass`
911
* added ControllerNameParser::build() which converts a controller short notation (a:b:c) to a class::method notation

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
139139
->info('profiler configuration')
140140
->canBeEnabled()
141141
->children()
142+
->booleanNode('collect')->defaultTrue()->end()
142143
->booleanNode('only_exceptions')->defaultFalse()->end()
143144
->booleanNode('only_master_requests')->defaultFalse()->end()
144145
->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ public function load(array $configs, ContainerBuilder $container)
9191
$this->registerValidationConfiguration($config['validation'], $container, $loader);
9292
$this->registerEsiConfiguration($config['esi'], $container, $loader);
9393
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
94-
95-
if (isset($config['profiler']) && isset($config['profiler']['enabled']) && $config['profiler']['enabled']) {
96-
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
97-
}
98-
94+
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
9995
$this->registerTranslatorConfiguration($config['translator'], $container);
10096

10197
if (isset($config['router'])) {
@@ -213,6 +209,10 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
213209
*/
214210
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
215211
{
212+
if (!$this->isConfigEnabled($container, $config)) {
213+
return;
214+
}
215+
216216
$loader->load('profiling.xml');
217217
$loader->load('collectors.xml');
218218

@@ -258,7 +258,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
258258
}
259259
}
260260

261-
if (!$this->isConfigEnabled($container, $config)) {
261+
if (!$config['collect']) {
262262
$container->getDefinition('profiler')->addMethodCall('disable', array());
263263
}
264264
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<xsd:element name="matcher" type="profiler_matcher" minOccurs="0" maxOccurs="1" />
5454
</xsd:all>
5555

56+
<xsd:attribute name="collect" type="xsd:string" />
5657
<xsd:attribute name="only-exceptions" type="xsd:string" />
5758
<xsd:attribute name="only-master-requests" type="xsd:string" />
5859
<xsd:attribute name="enabled" type="xsd:string" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ protected static function getBundleDefaultConfig()
111111
'username' => '',
112112
'password' => '',
113113
'lifetime' => 86400,
114+
'collect' => true,
114115
),
115116
'translator' => array(
116117
'enabled' => false,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
),
1616
'profiler' => array(
1717
'only_exceptions' => true,
18+
'enabled' => false,
1819
),
1920
'router' => array(
2021
'resource' => '%kernel.root_dir%/config/routing.xml',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'profiler' => array(
5+
'enabled' => true,
6+
),
7+
));

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<framework:csrf-protection enabled="true" field-name="_csrf" />
1111
<framework:form />
1212
<framework:esi enabled="true" />
13-
<framework:profiler only-exceptions="true" />
13+
<framework:profiler only-exceptions="true" enabled="false" />
1414
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
1515
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" save-path="/path/to/sessions" />
1616
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:profiler enabled="true" />
11+
</framework:config>
12+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ framework:
1111
enabled: true
1212
profiler:
1313
only_exceptions: true
14+
enabled: false
1415
router:
1516
resource: %kernel.root_dir%/config/routing.xml
1617
type: xml

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
profiler:
3+
enabled: true

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,20 @@ public function testEsi()
5454
$this->assertTrue($container->hasDefinition('esi'), '->registerEsiConfiguration() loads esi.xml');
5555
}
5656

57-
public function testProfiler()
57+
public function testEnabledProfiler()
5858
{
59-
$container = $this->createContainerFromFile('full');
59+
$container = $this->createContainerFromFile('profiler');
6060

6161
$this->assertTrue($container->hasDefinition('profiler'), '->registerProfilerConfiguration() loads profiling.xml');
6262
$this->assertTrue($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() loads collectors.xml');
63-
$this->assertTrue($container->getParameter('profiler_listener.only_exceptions'));
64-
$this->assertEquals('%profiler_listener.only_exceptions%', $container->getDefinition('profiler_listener')->getArgument(2));
6563
}
6664

6765
public function testDisabledProfiler()
6866
{
69-
$container = $this->createContainerFromFile('full_disabled');
67+
$container = $this->createContainerFromFile('full');
7068

7169
$this->assertFalse($container->hasDefinition('profiler'), '->registerProfilerConfiguration() does not load profiling.xml');
7270
$this->assertFalse($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() does not load collectors.xml');
73-
$this->assertFalse($container->hasParameter('profiler_listener.only_exceptions'));
7471
}
7572

7673
public function testRouter()

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testProfilerIsDisabled($insulate)
3333
$client->enableProfiler();
3434
$crawler = $client->request('GET', '/profiler');
3535
$profile = $client->getProfile();
36-
$this->assertFalse(is_object($profile));
36+
$this->assertTrue(is_object($profile));
3737

3838
$client->request('GET', '/profiler');
3939
$this->assertFalse($client->getProfile());

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Profiler/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ imports:
33

44
framework:
55
profiler:
6-
enabled: false
6+
enabled: true
7+
collect: false

0 commit comments

Comments
 (0)