8000 fixed the registration of the web profiler when the profiler is disabled · symfony/symfony@88ebd62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88ebd62

Browse files
committed
fixed the registration of the web profiler when the profiler is disabled
1 parent a11f901 commit 88ebd62

File tree

6 files changed

+66
-10
lines changed

6 files changed

+66
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
210210
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
211211
{
212212
if (!$this->isConfigEnabled($container, $config)) {
213+
// this is needed for the WebProfiler to work even if the profiler is disabled
214+
$container->setParameter('data_collector.templates', array());
215+
213216
return;
214217
}
215218

src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\HttpKernel\Profiler\Profiler;
1515
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
16+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1617
use Symfony\Component\HttpFoundation\Response;
1718

1819
/**
@@ -26,7 +27,7 @@ class ExceptionController
2627
protected $debug;
2728
protected $profiler;
2829

29-
public function __construct(Profiler $profiler, \Twig_Environment $twig, $debug)
30+
public function __construct(Profiler $profiler = null, \Twig_Environment $twig, $debug)
3031
{
3132
$this->profiler = $profiler;
3233
$this->twig = $twig;
@@ -42,6 +43,10 @@ public function __construct(Profiler $profiler, \Twig_Environment $twig, $debug)
4243
*/
4344
public function showAction($token)
4445
{
46+
if (null === $this->profiler) {
47+
throw new NotFoundHttpException('The profiler must be enabled.');
48+
}
49+
4550
$this->profiler->disable();
4651

4752
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
@@ -76,6 +81,10 @@ public function showAction($token)
7681
*/
7782
public function cssAction($token)
7883
{
84+
if (null === $this->profiler) {
85+
throw new NotFoundHttpException('The profiler must be enabled.');
86+
}
87+
7988
$this->profiler->disable();
8089

8190
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ProfilerController
4343
* @param array $templates The templates
4444
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
4545
*/
46-
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal')
46+
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal')
4747
{
4848
$this->generator = $generator;
4949
$this->profiler = $profiler;
@@ -59,6 +59,10 @@ public function __construct(UrlGeneratorInterface $generator, Profiler $profiler
5959
*/
6060
public function homeAction()
6161
{
62+
if (null === $this->profiler) {
63+
throw new NotFoundHttpException('The profiler must be enabled.');
64+
}
65+
6266
$this->profiler->disable();
6367

6468
return new RedirectResponse($this->generator->generate('_profiler_search_results', array('token' => 'empty', 'limit' => 10)));
@@ -76,6 +80,10 @@ public function homeAction()
7680
*/
7781
public function panelAction(Request $request, $token)
7882
{
83+
if (null === $this->profiler) {
84+
throw new NotFoundHttpException('The profiler must be enabled.');
85+
}
86+
7987
$this->profiler->disable();
8088

8189
$panel = $request->query->get('panel', 'request');
@@ -112,6 +120,10 @@ public function panelAction(Request $request, $token)
112120
*/
113121
public function exportAction($token)
114122
{
123+
if (null === $this->profiler) {
124+
throw new NotFoundHttpException('The profiler must be enabled.');
125+
}
126+
115127
$this->profiler->disable();
116128

117129
if (!$profile = $this->profiler->loadProfile($token)) {
@@ -131,6 +143,10 @@ public function exportAction($token)
131143
*/
132144
public function purgeAction()
133145
{
146+
if (null === $this->profiler) {
147+
throw new NotFoundHttpException('The profiler must be enabled.');
148+
}
149+
134150
$this->profiler->disable();
135151
$this->profiler->purge();
136152

@@ -146,6 +162,10 @@ public function purgeAction()
146162
*/
147163
public function importAction(Request $request)
148164
{
165+
if (null === $this->profiler) {
166+
throw new NotFoundHttpException('The profiler must be enabled.');
167+
}
168+
149169
$this->profiler->disable();
150170

151171
$file = $request->files->get('file');
@@ -170,6 +190,10 @@ public function importAction(Request $request)
170190
*/
171191
public function infoAction($about)
172192
{
193+
if (null === $this->profiler) {
194+
throw new NotFoundHttpException('The profiler must be enabled.');
195+
}
196+
173197
$this->profiler->disable();
174198

175199
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
@@ -187,6 +211,10 @@ public function infoAction($about)
187211
*/
188212
public function toolbarAction(Request $request, $token)
189213
{
214+
if (null === $this->profiler) {
215+
throw new NotFoundHttpException('The profiler must be enabled.');
216+
}
217+
190218
$session = $request->getSession();
191219

192220
if (null !== $session && $session->getFlashBag() instanceof AutoExpireFlashBag) {
@@ -234,6 +262,10 @@ public function toolbarAction(Request $request, $token)
234262
*/
235263
public function searchBarAction(Request $request)
236264
{
265+
if (null === $this->profiler) {
266+
throw new NotFoundHttpException('The profiler must be enabled.');
267+
}
268+
237269
$this->profiler->disable();
238270

239271
if (null === $session = $request->getSession()) {
@@ -275,6 +307,10 @@ public function searchBarAction(Request $request)
275307
*/
276308
public function searchResultsAction(Request $request, $token)
277309
{
310+
if (null === $this->profiler) {
311+
throw new NotFoundHttpException('The profiler must be enabled.');
312+
}
313+
278314
$this->profiler->disable();
279315

280316
$profile = $this->profiler->loadProfile($token);
@@ -309,6 +345,10 @@ public function searchResultsAction(Request $request, $token)
309345
*/
310346
public function searchAction(Request $request)
311347
{
348+
if (null === $this->profiler) {
349+
throw new NotFoundHttpException('The profiler must be enabled.');
350+
}
351+
312352
$this->profiler->disable();
313353

314354
$ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip'));
@@ -353,6 +393,10 @@ public function searchAction(Request $request)
353393
*/
354394
public function phpinfoAction()
355395
{
396+
if (null === $this->profiler) {
397+
throw new NotFoundHttpException('The profiler must be enabled.');
398+
}
399+
356400
$this->profiler->disable();
357401

358402
ob_start();

src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RouterController
3030
private $matcher;
3131
private $routes;
3232

33-
public function __construct(Profiler $profiler, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null)
33+
public function __construct(Profiler $profiler = null, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null)
3434
{
3535
$this->profiler = $profiler;
3636
$this->twig = $twig;
@@ -51,6 +51,10 @@ public function __construct(Profiler $profiler, \Twig_Environment $twig, UrlMatc
5151
*/
5252
public function panelAction($token)
5353
{
54+
if (null === $this->profiler) {
55+
throw new NotFoundHttpException('The profiler must be enabled.');
56+
}
57+
5458
$this->profiler->disable();
5559

5660
if (null === $this->matcher || null === $this->routes) {

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class WebProfilerExtension extends Extension
3939
*/
4040
public function load(array $configs, ContainerBuilder $container)
4141
{
42-
if (!$container->hasParameter('profiler.class')) {
43-
return;
44-
}
45-
4642
$configuration = $this->getConfiguration($configs, $container);
4743
$config = $this->processConfiguration($configuration, $configs);
4844

src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
<services>
1414
<service id="web_profiler.controller.profiler" class="%web_profiler.controller.profiler.class%">
1515
<argument type="service" id="router" on-invalid="null" />
16-
<argument type="service" id="profiler" />
16+
<argument type="service" id="profiler" on-invalid="null" />
1717
<argument type="service" id="twig" />
1818
<argument>%data_collector.templates%</argument>
1919
<argument>%web_profiler.debug_toolbar.position%</argument>
2020
</service>
2121

2222
<service id="web_profiler.controller.router" class="%web_profiler.controller.router.class%">
23-
<argument type="service" id="profiler" />
23+
<argument type="service" id="profiler" on-invalid="null" />
2424
<argument type="service" id="twig" />
2525
<argument type="service" id="router" on-invalid="null" />
2626
</service>
2727

2828
<service id="web_profiler.controller.exception" class="%web_profiler.controller.exception.class%">
29-
<argument type="service" id="profiler" />
29+
<argument type="service" id="profiler" on-invalid="null" />
3030
<argument type="service" id="twig" />
3131
<argument>%kernel.debug%</argument>
3232
</service>

0 commit comments

Comments
 (0)
0