diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
index 76453a37bfb41..0e9393ca29308 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 d75107355a213..8a7391789c5dc 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -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()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index 2848714cd952e..ceaab3db857a5 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -209,6 +209,13 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
*/
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;
+ }
+
$loader->load('profiling.xml');
$loader->load('collectors.xml');
@@ -254,7 +261,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
}
}
- 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 675a24b2c620f..4b235051f82d5 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 625b0229ff62a..55c9b55bd5608 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
@@ -111,6 +111,7 @@ protected static function getBundleDefaultConfig()
'username' => '',
'password' => '',
'lifetime' => 86400,
+ 'collect' => true,
),
'translator' => array(
'enabled' => false,
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 0000000000000..6615aa74ce558
--- /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/profiler.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/profiler.xml
new file mode 100644
index 0000000000000..f3b3095ccd951
--- /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/profiler.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/profiler.yml
new file mode 100644
index 0000000000000..9052a2bdfb0c8
--- /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 205d323d58199..172c95f57f364 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -54,17 +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');
- $calls = $container->getDefinition('profiler')->getMethodCalls();
- $this->assertEquals('disable', $calls[0][0]);
+ $this->assertFalse($container->hasDefinition('profiler'), '->registerProfilerConfiguration() does not load profiling.xml');
+ $this->assertFalse($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() does not load collectors.xml');
}
public function testRouter()
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 7c2f516966246..12ce67e548ea0 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
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
index 64108d58ad695..c89f3464139ae 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
@@ -13,6 +13,7 @@
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 @@ public function __construct(Profiler $profiler, \Twig_Environment $twig, $debug)
*/
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 @@ public function showAction($token)
*/
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 1b2d8ded1f204..31bda0393bc04 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 @@ public function __construct(UrlGeneratorInterface $generator, Profiler $profiler
*/
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 @@ public function homeAction()
*/
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 @@ public function panelAction(Request $request, $token)
*/
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 @@ public function exportAction($token)
*/
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 @@ public function purgeAction()
*/
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 @@ public function importAction(Request $request)
*/
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 @@ public function infoAction($about)
*/
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 @@ public function toolbarAction(Request $request, $token)
*/
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 @@ public function searchBarAction(Request $request)
*/
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 @@ public function searchResultsAction(Request $request, $token)
*/
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 @@ public function searchAction(Request $request)
*/
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 ab48e51d3bb71..55fd7d1d33372 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 @@ public function __construct(Profiler $profiler, \Twig_Environment $twig, UrlMatc
*/
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/Resources/config/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml
index 22d12409cdc5a..874ba8b216244 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%
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php
index 4169d495a1722..f9dd1eacd91c8 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php
@@ -61,6 +61,7 @@ protected function setUp()
$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());