[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
This commit is contained in:
parent
f675dd8faa
commit
a11f9017aa
@ -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
|
||||
|
@ -139,6 +139,7 @@ class Configuration implements ConfigurationInterface
|
||||
->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()
|
||||
|
@ -91,11 +91,7 @@ class FrameworkExtension extends Extension
|
||||
$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'])) {
|
||||
@ -213,6 +209,10 @@ class FrameworkExtension extends Extension
|
||||
*/
|
||||
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
if (!$this->isConfigEnabled($container, $config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader->load('profiling.xml');
|
||||
$loader->load('collectors.xml');
|
||||
|
||||
@ -258,7 +258,7 @@ class FrameworkExtension extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->isConfigEnabled($container, $config)) {
|
||||
if (!$config['collect']) {
|
||||
$container->getDefinition('profiler')->addMethodCall('disable', array());
|
||||
}
|
||||
}
|
||||
|
@ -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" />
|
||||
|
@ -111,6 +111,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'lifetime' => 86400,
|
||||
'collect' => true,
|
||||
),
|
||||
'translator' => array(
|
||||
'enabled' => false,
|
||||
|
@ -15,6 +15,7 @@ $container->loadFromExtension('framework', array(
|
||||
),
|
||||
'profiler' => array(
|
||||
'only_exceptions' => true,
|
||||
'enabled' => false,
|
||||
),
|
||||
'router' => array(
|
||||
'resource' => '%kernel.root_dir%/config/routing.xml',
|
||||
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
$container->loadFromExtension('framework', array(
|
||||
'secret' => 's3cr3t',
|
||||
'default_locale' => 'fr',
|
||||
'form' => null,
|
||||
'trust_proxy_headers' => true,
|
||||
'trusted_proxies' => array('127.0.0.1', '10.0.0.1'),
|
||||
'csrf_protection' => array(
|
||||
'enabled' => true,
|
||||
'field_name' => '_csrf',
|
||||
),
|
||||
'esi' => array(
|
||||
'enabled' => true,
|
||||
),
|
||||
'profiler' => array(
|
||||
'only_exceptions' => true,
|
||||
'enabled' => false,
|
||||
),
|
||||
'router' => array(
|
||||
'resource' => '%kernel.root_dir%/config/routing.xml',
|
||||
'type' => 'xml',
|
||||
),
|
||||
'session' => array(
|
||||
'storage_id' => 'session.storage.native',
|
||||
'handler_id' => 'session.handler.native_file',
|
||||
'name' => '_SYMFONY',
|
||||
'lifetime' => 86400,
|
||||
'path' => '/',
|
||||
'domain' => 'example.com',
|
||||
'secure' => true,
|
||||
'httponly' => true,
|
||||
'gc_maxlifetime' => 90000,
|
||||
'gc_divisor' => 108,
|
||||
'gc_probability' => 1,
|
||||
'save_path' => '/path/to/sessions',
|
||||
),
|
||||
'templating' => array(
|
||||
'assets_version' => 'SomeVersionScheme',
|
||||
'assets_base_urls' => 'http://cdn.example.com',
|
||||
'cache' => '/path/to/cache',
|
||||
'engines' => array('php', 'twig'),
|
||||
'loader' => array('loader.foo', 'loader.bar'),
|
||||
'packages' => array(
|
||||
'images' => array(
|
||||
'version' => '1.0.0',
|
||||
'base_urls' => array('http://images1.example.com', 'http://images2.example.com'),
|
||||
),
|
||||
'foo' => array(
|
||||
'version' => '1.0.0',
|
||||
),
|
||||
'bar' => array(
|
||||
'base_urls' => array('http://bar1.example.com', 'http://bar2.example.com'),
|
||||
),
|
||||
),
|
||||
'form' => array(
|
||||
'resources' => array('theme1', 'theme2')
|
||||
),
|
||||
),
|
||||
'translator' => array(
|
||||
'enabled' => true,
|
||||
'fallback' => 'fr',
|
||||
),
|
||||
'validation' => array(
|
||||
'enabled' => true,
|
||||
'cache' => 'apc',
|
||||
),
|
||||
'annotations' => array(
|
||||
'cache' => 'file',
|
||||
'debug' => true,
|
||||
'file_cache_dir' => '%kernel.cache_dir%/annotations',
|
||||
),
|
||||
'ide' => 'file%%link%%format'
|
||||
));
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$container->loadFromExtension('framework', array(
|
||||
'profiler' => array(
|
||||
'enabled' => true,
|
||||
),
|
||||
));
|
@ -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" >
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?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 secret="s3cr3t" ide="file%%link%%format" default-locale="fr" trust-proxy-headers="true" trusted-proxies="127.0.0.1, 10.0.0.1">
|
||||
<framework:csrf-protection enabled="true" field-name="_csrf" />
|
||||
<framework:form />
|
||||
<framework:esi enabled="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" >
|
||||
<framework:loader>loader.foo</framework:loader>
|
||||
<framework:loader>loader.bar</framework:loader>
|
||||
<framework:engine>php</framework:engine>
|
||||
<framework:engine>twig</framework:engine>
|
||||
<framework:assets-base-url>http://cdn.example.com</framework:assets-base-url>
|
||||
<framework:package name="images" version="1.0.0">
|
||||
<framework:base-url>http://images1.example.com</framework:base-url>
|
||||
<framework:base-url>http://images2.example.com</framework:base-url>
|
||||
</framework:package>
|
||||
<framework:package name="foo" version="1.0.0" />
|
||||
<framework:package name="bar">
|
||||
<framework:base-url>http://bar1.example.com</framework:base-url>
|
||||
<framework:base-url>http://bar2.example.com</framework:base-url>
|
||||
</framework:package>
|
||||
<framework:form>
|
||||
<framework:resource>theme1</framework:resource>
|
||||
<framework:resource>theme2</framework:resource>
|
||||
</framework:form>
|
||||
</framework:templating>
|
||||
<framework:translator enabled="true" fallback="fr" />
|
||||
<framework:validation enabled="true" cache="apc" />
|
||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||
</framework:config>
|
||||
</container>
|
@ -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>
|
@ -11,6 +11,7 @@ framework:
|
||||
enabled: true
|
||||
profiler:
|
||||
only_exceptions: true
|
||||
enabled: false
|
||||
router:
|
||||
resource: %kernel.root_dir%/config/routing.xml
|
||||
type: xml
|
||||
|
@ -1,57 +0,0 @@
|
||||
framework:
|
||||
secret: s3cr3t
|
||||
default_locale: fr
|
||||
form: ~
|
||||
trust_proxy_headers: true
|
||||
trusted_proxies: ['127.0.0.1', '10.0.0.1']
|
||||
csrf_protection:
|
||||
enabled: true
|
||||
field_name: _csrf
|
||||
esi:
|
||||
enabled: true
|
||||
profiler:
|
||||
only_exceptions: true
|
||||
enabled: false
|
||||
router:
|
||||
resource: %kernel.root_dir%/config/routing.xml
|
||||
type: xml
|
||||
session:
|
||||
storage_id: session.storage.native
|
||||
handler_id: session.handler.native_file
|
||||
name: _SYMFONY
|
||||
lifetime: 86400
|
||||
path: /
|
||||
domain: example.com
|
||||
secure: true
|
||||
httponly: true
|
||||
gc_probability: 1
|
||||
gc_divisor: 108
|
||||
gc_maxlifetime: 90000
|
||||
save_path: /path/to/sessions
|
||||
templating:
|
||||
assets_version: SomeVersionScheme
|
||||
assets_base_urls: http://cdn.example.com
|
||||
engines: [php, twig]
|
||||
loader: [loader.foo, loader.bar]
|
||||
cache: /path/to/cache
|
||||
packages:
|
||||
images:
|
||||
version: 1.0.0
|
||||
base_urls: ["http://images1.example.com", "http://images2.example.com"]
|
||||
foo:
|
||||
version: 1.0.0
|
||||
bar:
|
||||
base_urls: ["http://images1.example.com", "http://images2.example.com"]
|
||||
form:
|
||||
resources: [theme1, theme2]
|
||||
translator:
|
||||
enabled: true
|
||||
fallback: fr
|
||||
validation:
|
||||
enabled: true
|
||||
cache: apc
|
||||
annotations:
|
||||
cache: file
|
||||
debug: true
|
||||
file_cache_dir: %kernel.cache_dir%/annotations
|
||||
ide: file%%link%%format
|
@ -0,0 +1,3 @@
|
||||
framework:
|
||||
profiler:
|
||||
enabled: true
|
@ -54,23 +54,20 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$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()
|
||||
|
@ -33,7 +33,7 @@ class ProfilerTest extends WebTestCase
|
||||
$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());
|
||||
|
@ -3,4 +3,5 @@ imports:
|
||||
|
||||
framework:
|
||||
profiler:
|
||||
enabled: false
|
||||
enabled: true
|
||||
collect: false
|
||||
|
Reference in New Issue
Block a user