From f675dd8faa62cd6486d458fc3c721039da45de81 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Thu, 14 Feb 2013 17:42:17 +0200 Subject: [PATCH 1/3] Truly disabled profiler in prod --- .../FrameworkExtension.php | 6 +- .../DependencyInjection/Fixtures/php/full.php | 1 - .../Fixtures/php/full_disabled.php | 74 +++++++++++++++++++ .../DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Fixtures/xml/full_disabled.xml | 40 ++++++++++ .../DependencyInjection/Fixtures/yml/full.yml | 1 - .../Fixtures/yml/full_disabled.yml | 57 ++++++++++++++ .../FrameworkExtensionTest.php | 10 ++- .../Tests/Functional/ProfilerTest.php | 2 +- .../WebProfilerExtension.php | 4 + .../WebProfilerExtensionTest.php | 1 + 11 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 2848714cd9..4ce9c96fd1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -91,7 +91,11 @@ class FrameworkExtension extends Extension $this->registerValidationConfiguration($config['validation'], $container, $loader); $this->registerEsiConfiguration($config['esi'], $container, $loader); $this->registerFragmentsConfiguration($config['fragments'], $container, $loader); - $this->registerProfilerConfiguration($config['profiler'], $container, $loader); + + if (isset($config['profiler']) && isset($config['profiler']['enabled']) && $config['profiler']['enabled']) { + $this->registerProfilerConfiguration($config['profiler'], $container, $loader); + } + $this->registerTranslatorConfiguration($config['translator'], $container); if (isset($config['router'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index c4eff93492..e1b879443f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -15,7 +15,6 @@ $container->loadFromExtension('framework', array( ), 'profiler' => array( 'only_exceptions' => true, - 'enabled' => false, ), 'router' => array( 'resource' => '%kernel.root_dir%/config/routing.xml', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php new file mode 100644 index 0000000000..27988e2c2e --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php @@ -0,0 +1,74 @@ +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' +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 8fd3e9b652..6fa646031a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml new file mode 100644 index 0000000000..eacd416597 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + loader.foo + loader.bar + php + twig + http://cdn.example.com + + http://images1.example.com + http://images2.example.com + + + + http://bar1.example.com + http://bar2.example.com + + + theme1 + theme2 + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index d013063916..dec20e7989 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -11,7 +11,6 @@ framework: enabled: true profiler: only_exceptions: true - enabled: false router: resource: %kernel.root_dir%/config/routing.xml type: xml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml new file mode 100644 index 0000000000..9eddd249d5 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml @@ -0,0 +1,57 @@ +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 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 205d323d58..c3bdfd59cc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -62,9 +62,15 @@ abstract class FrameworkExtensionTest extends TestCase $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)); + } - $calls = $container->getDefinition('profiler')->getMethodCalls(); - $this->assertEquals('disable', $calls[0][0]); + public function testDisabledProfiler() + { + $container = $this->createContainerFromFile('full_disabled'); + + $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() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php index d4eb927ff8..6465272133 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php @@ -33,7 +33,7 @@ class ProfilerTest extends WebTestCase $client->enableProfiler(); $crawler = $client->request('GET', '/profiler'); $profile = $client->getProfile(); - $this->assertTrue(is_object($profile)); + $this->assertFalse(is_object($profile)); $client->request('GET', '/profiler'); $this->assertFalse($client->getProfile()); diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index e4b4cb72a0..57ec1c15b2 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -39,6 +39,10 @@ class WebProfilerExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { + if (!$container->hasParameter('profiler.class')) { + return; + } + $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index 4169d495a1..f9dd1eacd9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -61,6 +61,7 @@ class WebProfilerExtensionTest extends TestCase $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.root_dir', __DIR__); + $this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')); $this->container->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')) ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface'))); $this->container->setParameter('data_collector.templates', array()); From a11f9017aa6c21f2bd3a97c2dd16a30c3e735f49 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 26 Apr 2013 15:53:58 +0200 Subject: [PATCH 2/3] [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 --- .../Bundle/FrameworkBundle/CHANGELOG.md | 2 + .../DependencyInjection/Configuration.php | 1 + .../FrameworkExtension.php | 12 +-- .../Resources/config/schema/symfony-1.0.xsd | 1 + .../DependencyInjection/ConfigurationTest.php | 1 + .../DependencyInjection/Fixtures/php/full.php | 1 + .../Fixtures/php/full_disabled.php | 74 ------------------- .../Fixtures/php/profiler.php | 7 ++ .../DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Fixtures/xml/full_disabled.xml | 40 ---------- .../Fixtures/xml/profiler.xml | 12 +++ .../DependencyInjection/Fixtures/yml/full.yml | 1 + .../Fixtures/yml/full_disabled.yml | 57 -------------- .../Fixtures/yml/profiler.yml | 3 + .../FrameworkExtensionTest.php | 9 +-- .../Tests/Functional/ProfilerTest.php | 2 +- .../Tests/Functional/app/Profiler/config.yml | 3 +- 17 files changed, 42 insertions(+), 186 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/profiler.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/profiler.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/profiler.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 76453a37bf..0e9393ca29 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -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 diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index d75107355a..8a7391789c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -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() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 4ce9c96fd1..8d37361575 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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()); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 675a24b2c6..4b235051f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -53,6 +53,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 625b0229ff..55c9b55bd5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -111,6 +111,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'username' => '', 'password' => '', 'lifetime' => 86400, + 'collect' => true, ), 'translator' => array( 'enabled' => false, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index e1b879443f..c4eff93492 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -15,6 +15,7 @@ $container->loadFromExtension('framework', array( ), 'profiler' => array( 'only_exceptions' => true, + 'enabled' => false, ), 'router' => array( 'resource' => '%kernel.root_dir%/config/routing.xml', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php deleted file mode 100644 index 27988e2c2e..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full_disabled.php +++ /dev/null @@ -1,74 +0,0 @@ -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' -)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/profiler.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/profiler.php new file mode 100644 index 0000000000..6615aa74ce --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/profiler.php @@ -0,0 +1,7 @@ +loadFromExtension('framework', array( + 'profiler' => array( + 'enabled' => true, + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 6fa646031a..8fd3e9b652 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml deleted file mode 100644 index eacd416597..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full_disabled.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - loader.foo - loader.bar - php - twig - http://cdn.example.com - - http://images1.example.com - http://images2.example.com - - - - http://bar1.example.com - http://bar2.example.com - - - theme1 - theme2 - - - - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/profiler.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/profiler.xml new file mode 100644 index 0000000000..f3b3095ccd --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/profiler.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index dec20e7989..d013063916 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -11,6 +11,7 @@ framework: enabled: true profiler: only_exceptions: true + enabled: false router: resource: %kernel.root_dir%/config/routing.xml type: xml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml deleted file mode 100644 index 9eddd249d5..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full_disabled.yml +++ /dev/null @@ -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 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/profiler.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/profiler.yml new file mode 100644 index 0000000000..9052a2bdfb --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/profiler.yml @@ -0,0 +1,3 @@ +framework: + profiler: + enabled: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index c3bdfd59cc..172c95f57f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -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() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php index 6465272133..d4eb927ff8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php @@ -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()); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Profiler/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Profiler/config.yml index 7c2f516966..12ce67e548 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Profiler/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Profiler/config.yml @@ -3,4 +3,5 @@ imports: framework: profiler: - enabled: false + enabled: true + collect: false From 88ebd62e1ccff00a2292e0a4d2c1003ca930c9b6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 26 Apr 2013 16:27:29 +0200 Subject: [PATCH 3/3] fixed the registration of the web profiler when the profiler is disabled --- .../FrameworkExtension.php | 3 ++ .../Controller/ExceptionController.php | 11 ++++- .../Controller/ProfilerController.php | 46 ++++++++++++++++++- .../Controller/RouterController.php | 6 ++- .../WebProfilerExtension.php | 4 -- .../Resources/config/profiler.xml | 6 +-- 6 files changed, 66 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 8d37361575..ceaab3db85 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -210,6 +210,9 @@ class FrameworkExtension extends Extension private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { if (!$this->isConfigEnabled($container, $config)) { + // this is needed for the WebProfiler to work even if the profiler is disabled + $container->setParameter('data_collector.templates', array()); + return; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index 64108d58ad..c89f346413 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Controller; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Debug\ExceptionHandler; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; /** @@ -26,7 +27,7 @@ class ExceptionController protected $debug; protected $profiler; - public function __construct(Profiler $profiler, \Twig_Environment $twig, $debug) + public function __construct(Profiler $profiler = null, \Twig_Environment $twig, $debug) { $this->profiler = $profiler; $this->twig = $twig; @@ -42,6 +43,10 @@ class ExceptionController */ public function showAction($token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException(); @@ -76,6 +81,10 @@ class ExceptionController */ public function cssAction($token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException(); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 1b2d8ded1f..31bda0393b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -43,7 +43,7 @@ class ProfilerController * @param array $templates The templates * @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration) */ - public function __construct(UrlGeneratorInterface $generator, Profiler $profiler, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal') + public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal') { $this->generator = $generator; $this->profiler = $profiler; @@ -59,6 +59,10 @@ class ProfilerController */ public function homeAction() { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); return new RedirectResponse($this->generator->generate('_profiler_search_results', array('token' => 'empty', 'limit' => 10))); @@ -76,6 +80,10 @@ class ProfilerController */ public function panelAction(Request $request, $token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $panel = $request->query->get('panel', 'request'); @@ -112,6 +120,10 @@ class ProfilerController */ public function exportAction($token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); if (!$profile = $this->profiler->loadProfile($token)) { @@ -131,6 +143,10 @@ class ProfilerController */ public function purgeAction() { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $this->profiler->purge(); @@ -146,6 +162,10 @@ class ProfilerController */ public function importAction(Request $request) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $file = $request->files->get('file'); @@ -170,6 +190,10 @@ class ProfilerController */ public function infoAction($about) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array( @@ -187,6 +211,10 @@ class ProfilerController */ public function toolbarAction(Request $request, $token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $session = $request->getSession(); if (null !== $session && $session->getFlashBag() instanceof AutoExpireFlashBag) { @@ -234,6 +262,10 @@ class ProfilerController */ public function searchBarAction(Request $request) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); if (null === $session = $request->getSession()) { @@ -275,6 +307,10 @@ class ProfilerController */ public function searchResultsAction(Request $request, $token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $profile = $this->profiler->loadProfile($token); @@ -309,6 +345,10 @@ class ProfilerController */ public function searchAction(Request $request) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); $ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip')); @@ -353,6 +393,10 @@ class ProfilerController */ public function phpinfoAction() { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); ob_start(); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php index ab48e51d3b..55fd7d1d33 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php @@ -30,7 +30,7 @@ class RouterController private $matcher; private $routes; - public function __construct(Profiler $profiler, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) + public function __construct(Profiler $profiler = null, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) { $this->profiler = $profiler; $this->twig = $twig; @@ -51,6 +51,10 @@ class RouterController */ public function panelAction($token) { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + $this->profiler->disable(); if (null === $this->matcher || null === $this->routes) { diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 57ec1c15b2..e4b4cb72a0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -39,10 +39,6 @@ class WebProfilerExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - if (!$container->hasParameter('profiler.class')) { - return; - } - $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml index 22d12409cd..874ba8b216 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml @@ -13,20 +13,20 @@ - + %data_collector.templates% %web_profiler.debug_toolbar.position% - + - + %kernel.debug%