From 88ebd62e1ccff00a2292e0a4d2c1003ca930c9b6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 26 Apr 2013 16:27:29 +0200 Subject: [PATCH] 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 8d373615758e..ceaab3db857a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -210,6 +210,9 @@ 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; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index 64108d58ad69..c89f3464139a 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 1b2d8ded1f20..31bda0393bc0 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 ab48e51d3bb7..55fd7d1d3337 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/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 57ec1c15b29f..e4b4cb72a078 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 22d12409cdc5..874ba8b21624 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%