Skip to content

Commit

Permalink
[FrameworkBundle] added a way to disable the profiler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Apr 26, 2013
1 parent f675dd8 commit a11f901
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 186 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
2.3.0
-----

* [BC BREAK] added a way to disable the profiler (when disabling the profiler, it is now completely removed)
To get the same "disabled" behavior as before, set `enabled` to `true` and `collect` to `false`
* [BC BREAK] the `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass` was moved
to `Component\HttpKernel\DependencyInjection\RegisterListenersPass`
* added ControllerNameParser::build() which converts a controller short notation (a:b:c) to a class::method notation
Expand Down
Expand Up @@ -139,6 +139,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
->info('profiler configuration')
->canBeEnabled()
->children()
->booleanNode('collect')->defaultTrue()->end()
->booleanNode('only_exceptions')->defaultFalse()->end()
->booleanNode('only_master_requests')->defaultFalse()->end()
->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()
Expand Down
Expand Up @@ -91,11 +91,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerValidationConfiguration($config['validation'], $container, $loader);
$this->registerEsiConfiguration($config['esi'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);

if (isset($config['profiler']) && isset($config['profiler']['enabled']) && $config['profiler']['enabled']) {
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
}

$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container);

if (isset($config['router'])) {
Expand Down Expand Up @@ -213,6 +209,10 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
*/
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}

$loader->load('profiling.xml');
$loader->load('collectors.xml');

Expand Down Expand Up @@ -258,7 +258,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
}
}

if (!$this->isConfigEnabled($container, $config)) {
if (!$config['collect']) {
$container->getDefinition('profiler')->addMethodCall('disable', array());
}
}
Expand Down
Expand Up @@ -53,6 +53,7 @@
<xsd:element name="matcher" type="profiler_matcher" minOccurs="0" maxOccurs="1" />
</xsd:all>

<xsd:attribute name="collect" type="xsd:string" />
<xsd:attribute name="only-exceptions" type="xsd:string" />
<xsd:attribute name="only-master-requests" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:string" />
Expand Down
Expand Up @@ -111,6 +111,7 @@ protected static function getBundleDefaultConfig()
'username' => '',
'password' => '',
'lifetime' => 86400,
'collect' => true,
),
'translator' => array(
'enabled' => false,
Expand Down
Expand Up @@ -15,6 +15,7 @@
),
'profiler' => array(
'only_exceptions' => true,
'enabled' => false,
),
'router' => array(
'resource' => '%kernel.root_dir%/config/routing.xml',
Expand Down

This file was deleted.

@@ -0,0 +1,7 @@
<?php

$container->loadFromExtension('framework', array(
'profiler' => array(
'enabled' => true,
),
));
Expand Up @@ -10,7 +10,7 @@
<framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form />
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" />
<framework:profiler only-exceptions="true" enabled="false" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
<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" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
Expand Down

This file was deleted.

@@ -0,0 +1,12 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:profiler enabled="true" />
</framework:config>
</container>
Expand Up @@ -11,6 +11,7 @@ framework:
enabled: true
profiler:
only_exceptions: true
enabled: false
router:
resource: %kernel.root_dir%/config/routing.xml
type: xml
Expand Down

This file was deleted.

@@ -0,0 +1,3 @@
framework:
profiler:
enabled: true
Expand Up @@ -54,23 +54,20 @@ public function testEsi()
$this->assertTrue($container->hasDefinition('esi'), '->registerEsiConfiguration() loads esi.xml');
}

public function testProfiler()
public function testEnabledProfiler()
{
$container = $this->createContainerFromFile('full');
$container = $this->createContainerFromFile('profiler');

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

public function testDisabledProfiler()
{
$container = $this->createContainerFromFile('full_disabled');
$container = $this->createContainerFromFile('full');

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

public function testRouter()
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function testProfilerIsDisabled($insulate)
$client->enableProfiler();
$crawler = $client->request('GET', '/profiler');
$profile = $client->getProfile();
$this->assertFalse(is_object($profile));
$this->assertTrue(is_object($profile));

$client->request('GET', '/profiler');
$this->assertFalse($client->getProfile());
Expand Down
Expand Up @@ -3,4 +3,5 @@ imports:

framework:
profiler:
enabled: false
enabled: true
collect: false

0 comments on commit a11f901

Please sign in to comment.