From 81939136adf084646d35d8213bdd5864e28c15ad Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:15:37 +0200 Subject: [PATCH] [WebProfilerBundle] Fixed errors if the session is not configured --- .../Controller/ProfilerController.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index f508869265a1..74932ed08ddd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -129,8 +129,10 @@ public function toolbarAction($token, $position = null) { $request = $this->container->get('request'); - // keep current flashes for one more request - $request->getSession()->setFlashes($request->getSession()->getFlashes()); + if ($session = $request->getSession()) { + // keep current flashes for one more request + $session->setFlashes($request->getSession()->getFlashes()); + } if (null === $token) { return new Response(); @@ -175,17 +177,20 @@ public function searchBarAction() $profiler = $this->container->get('profiler'); $profiler->disable(); - $session = $this->container->get('request')->getSession(); - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); + if (!$session = $this->container->get('request')->getSession()) { + return new Response(null, 200); + } + + $ip = $session->get('_profiler_search_ip'); + $url = $session->get('_profiler_search_url'); $limit = $session->get('_profiler_search_limit'); $token = $session->get('_profiler_search_token'); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:search.html.twig', array( - 'token' => $token, - 'ip' => $ip, - 'url' => $url, - 'limit' => $limit, + 'token' => $token, + 'ip' => $ip, + 'url' => $url, + 'limit' => $limit, )); } @@ -201,9 +206,12 @@ public function searchResultsAction($token) $pofiler = $profiler->loadFromToken($token); - $session = $this->container->get('request')->getSession(); - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); + if (!$session = $this->container->get('request')->getSession()) { + throw new \RuntimeException('To access to search, activate the session in your configuration.'); + } + + $ip = $session->get('_profiler_search_ip'); + $url = $session->get('_profiler_search_url'); $limit = $session->get('_profiler_search_limit'); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:results.html.twig', array(