@@ -54,11 +54,7 @@ public function __construct(UrlGeneratorInterface $generator, Profiler $profiler
54
54
*/
55
55
public function homeAction ()
56
56
{
57
- if (null === $ this ->profiler ) {
58
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
59
- }
60
-
61
- $ this ->profiler ->disable ();
57
+ $ this ->denyAccessIfProfilerDisabled ();
62
58
63
59
return new RedirectResponse ($ this ->generator ->generate ('_profiler_search_results ' , ['token ' => 'empty ' , 'limit ' => 10 ]), 302 , ['Content-Type ' => 'text/html ' ]);
64
60
}
@@ -75,11 +71,7 @@ public function homeAction()
75
71
*/
76
72
public function panelAction (Request $ request , $ token )
77
73
{
78
- if (null === $ this ->profiler ) {
79
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
80
- }
81
-
82
- $ this ->profiler ->disable ();
74
+ $ this ->denyAccessIfProfilerDisabled ();
83
75
84
76
if (null !== $ this ->cspHandler ) {
85
77
$ this ->cspHandler ->disableCsp ();
@@ -170,11 +162,7 @@ public function toolbarAction(Request $request, $token)
170
162
*/
171
163
public function searchBarAction (Request $ request )
172
164
{
173
- if (null === $ this ->profiler ) {
174
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
175
- }
176
-
177
- $ this ->profiler ->disable ();
165
+ $ this ->denyAccessIfProfilerDisabled ();
178
166
179
167
if (null !== $ this ->cspHandler ) {
180
168
$ this ->cspHandler ->disableCsp ();
@@ -231,11 +219,7 @@ public function searchBarAction(Request $request)
231
219
*/
232
220
public function searchResultsAction (Request $ request , $ token )
233
221
{
234
- if (null === $ this ->profiler ) {
235
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
236
- }
237
-
238
- $ this ->profiler ->disable ();
222
+ $ this ->denyAccessIfProfilerDisabled ();
239
223
240
224
if (null !== $ this ->cspHandler ) {
241
225
$ this ->cspHandler ->disableCsp ();
@@ -276,11 +260,7 @@ public function searchResultsAction(Request $request, $token)
276
260
*/
277
261
public function searchAction (Request $ request )
278
262
{
279
- if (null === $ this ->profiler ) {
280
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
281
- }
282
-
283
- $ this ->profiler ->disable ();
263
+ $ this ->denyAccessIfProfilerDisabled ();
284
264
285
265
$ ip = preg_replace ('/[^:\d\.]/ ' , '' , $ request ->query ->get ('ip ' ));
286
266
$ method = $ request ->query ->get ('method ' );
@@ -331,11 +311,7 @@ public function searchAction(Request $request)
331
311
*/
332
312
public function phpinfoAction ()
333
313
{
334
- if (null === $ this ->profiler ) {
335
- throw new NotFoundHttpException ('The profiler must be enabled. ' );
336
- }
337
-
338
- $ this ->profiler ->disable ();
314
+ $ this ->denyAccessIfProfilerDisabled ();
339
315
340
316
if (null !== $ this ->cspHandler ) {
341
317
$ this ->cspHandler ->disableCsp ();
@@ -394,6 +370,15 @@ protected function getTemplateManager()
394
370
395
371
return $ this ->templateManager ;
396
372
}
373
+
374
+ private function denyAccessIfProfilerDisabled ()
375
+ {
376
+ if (null === $ this ->profiler ) {
377
+ throw new NotFoundHttpException ('The profiler must be enabled. ' );
378
+ }
379
+
380
+ $ this ->profiler ->disable ();
381
+ }
397
382
398
383
private function renderWithCspNonces (Request $ request , $ template , $ variables , $ code = 200 , $ headers = ['Content-Type ' => 'text/html ' ])
399
384
{
0 commit comments