11
11
12
12
namespace Symfony \Bundle \WebProfilerBundle \Controller ;
13
13
14
- use Symfony \Component \DependencyInjection \ContainerAware ;
15
14
use Symfony \Component \HttpFoundation \Response ;
16
15
use Symfony \Component \HttpFoundation \RedirectResponse ;
17
16
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
17
+ use Symfony \Component \HttpKernel \Profiler \Profiler ;
18
18
use Symfony \Component \HttpFoundation \Session \Flash \AutoExpireFlashBag ;
19
19
use Symfony \Component \HttpFoundation \Request ;
20
20
use Symfony \Bundle \WebProfilerBundle \Profiler \TemplateManager ;
21
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
21
22
22
23
/**
23
24
* ProfilerController.
24
25
*
25
26
* @author Fabien Potencier <fabien@symfony.com>
26
27
*/
27
- class ProfilerController extends ContainerAware
28
+ class ProfilerController
28
29
{
29
- protected $ templateManager ;
30
+ private $ templateManager ;
31
+ private $ generator ;
32
+ private $ profiler ;
33
+ private $ twig ;
34
+ private $ templates ;
35
+ private $ toolbarPosition ;
36
+
37
+ public function __construct (UrlGeneratorInterface $ generator , Profiler $ profiler , \Twig_Environment $ twig , array $ templates , $ toolbarPosition = 'normal ' )
38
+ {
39
+ $ this ->generator = $ generator ;
40
+ $ this ->profiler = $ profiler ;
41
+ $ this ->twig = $ twig ;
42
+ $ this ->templates = $ templates ;
43
+ $ this ->toolbarPosition = $ toolbarPosition ;
44
+ }
30
45
31
46
/**
32
47
* Renders a profiler panel for the given token.
@@ -38,21 +53,20 @@ class ProfilerController extends ContainerAware
38
53
*/
39
54
public function panelAction (Request $ request , $ token )
40
55
{
41
- $ profiler = $ this ->container ->get ('profiler ' );
42
- $ profiler ->disable ();
56
+ $ this ->profiler ->disable ();
43
57
44
58
$ panel = $ request ->query ->get ('panel ' , 'request ' );
45
59
$ page = $ request ->query ->get ('page ' , 'home ' );
46
60
47
- if (!$ profile = $ profiler ->loadProfile ($ token )) {
48
- return $ this ->container -> get ( ' templating ' )-> renderResponse ( ' WebProfilerBundle: Profiler: info.html.twig ' , array ('about ' => 'no_token ' , 'token ' => $ token ));
61
+ if (!$ profile = $ this -> profiler ->loadProfile ($ token )) {
62
+ return new Response ( $ this ->twig -> render ( ' @WebProfiler/ Profiler/ info.html.twig ' , array ('about ' => 'no_token ' , 'token ' => $ token) ));
49
63
}
50
64
51
65
if (!$ profile ->hasCollector ($ panel )) {
52
66
throw new NotFoundHttpException (sprintf ('Panel "%s" is not available for token "%s". ' , $ panel , $ token ));
53
67
}
54
68
55
- return $ this ->container -> get ( ' templating ' )-> renderResponse ($ this ->getTemplateManager ()->getName ($ profile , $ panel ), array (
69
+ return new Response ( $ this ->twig -> render ($ this ->getTemplateManager ()->getName ($ profile , $ panel ), array (
56
70
'token ' => $ token ,
57
71
'profile ' => $ profile ,
58
72
'collector ' => $ profile ->getCollector ($ panel ),
@@ -61,7 +75,9 @@ public function panelAction(Request $request, $token)
61
75
'request ' => $ request ,
62
76
'templates ' => $ this ->getTemplateManager ()->getTemplates ($ profile ),
63
77
'is_ajax ' => $ request ->isXmlHttpRequest (),
64
- ));
78
+ // for BC compatibility
79
+ 'app ' => array ('request ' => $ request ),
80
+ )));
65
81
}
66
82
67
83
/**
@@ -73,14 +89,13 @@ public function panelAction(Request $request, $token)
73
89
*/
74
90
public function exportAction ($ token )
75
91
{
76
- $ profiler = $ this ->container ->get ('profiler ' );
77
- $ profiler ->disable ();
92
+ $ this ->profiler ->disable ();
78
93
79
- if (!$ profile = $ profiler ->loadProfile ($ token )) {
94
+ if (!$ profile = $ this -> profiler ->loadProfile ($ token )) {
80
95
throw new NotFoundHttpException (sprintf ('Token "%s" does not exist. ' , $ token ));
81
96
}
82
97
83
- return new Response ($ profiler ->export ($ profile ), 200 , array (
98
+ return new Response ($ this -> profiler ->export ($ profile ), 200 , array (
84
99
'Content-Type ' => 'text/plain ' ,
85
100
'Content-Disposition ' => 'attachment; filename= ' .$ token .'.txt ' ,
86
101
));
@@ -93,11 +108,10 @@ public function exportAction($token)
93
108
*/
94
109
public function purgeAction ()
95
110
{
96
- $ profiler = $ this ->container ->get ('profiler ' );
97
- $ profiler ->disable ();
98
- $ profiler ->purge ();
111
+ $ this ->profiler ->disable ();
112
+ $ this ->profiler ->purge ();
99
113
100
- return new RedirectResponse ($ this ->container -> get ( ' router ' ) ->generate ('_profiler_info ' , array ('about ' => 'purge ' )));
114
+ return new RedirectResponse ($ this ->generator ->generate ('_profiler_info ' , array ('about ' => 'purge ' )));
101
115
}
102
116
103
117
/**
@@ -107,22 +121,19 @@ public function purgeAction()
107
121
*/
108
122
public function importAction (Request $ request )
109
123
{
110
- $ profiler = $ this ->container ->get ('profiler ' );
111
- $ profiler ->disable ();
112
-
113
- $ router = $ this ->container ->get ('router ' );
124
+ $ this ->profiler ->disable ();
114
125
115
126
$ file = $ request ->files ->get ('file ' );
116
127
117
128
if (empty ($ file ) || !$ file ->isValid ()) {
118
129
return new RedirectResponse ($ router ->generate ('_profiler_info ' , array ('about ' => 'upload_error ' )));
119
130
}
120
131
121
- if (!$ profile = $ profiler ->import (file_get_contents ($ file ->getPathname ()))) {
122
- return new RedirectResponse ($ router ->generate ('_profiler_info ' , array ('about ' => 'already_exists ' )));
132
+ if (!$ profile = $ this -> profiler ->import (file_get_contents ($ file ->getPathname ()))) {
133
+ return new RedirectResponse ($ this -> generator ->generate ('_profiler_info ' , array ('about ' => 'already_exists ' )));
123
134
}
124
135
125
- return new RedirectResponse ($ router ->generate ('_profiler ' , array ('token ' => $ profile ->getToken ())));
136
+ return new RedirectResponse ($ this -> generator ->generate ('_profiler ' , array ('token ' => $ profile ->getToken ())));
126
137
}
127
138
128
139
/**
@@ -134,12 +145,11 @@ public function importAction(Request $request)
134
145
*/
135
146
public function infoAction ($ about )
136
147
{
137
- $ profiler = $ this ->container ->get ('profiler ' );
138
- $ profiler ->disable ();
148
+ $ this ->profiler ->disable ();
139
149
140
- return $ this ->container -> get ( ' templating ' )-> renderResponse ( ' WebProfilerBundle: Profiler: info.html.twig ' , array (
150
+ return new Response ( $ this ->twig -> render ( ' @WebProfiler/ Profiler/ info.html.twig ' , array (
141
151
'about ' => $ about
142
- ));
152
+ ))) ;
143
153
}
144
154
145
155
/**
@@ -164,31 +174,30 @@ public function toolbarAction(Request $request, $token, $position = null)
164
174
return new Response ();
165
175
}
166
176
167
- $ profiler = $ this ->container ->get ('profiler ' );
168
- $ profiler ->disable ();
177
+ $ this ->profiler ->disable ();
169
178
170
- if (!$ profile = $ profiler ->loadProfile ($ token )) {
179
+ if (!$ profile = $ this -> profiler ->loadProfile ($ token )) {
171
180
return new Response ();
172
181
}
173
182
174
183
if (null === $ position ) {
175
- $ position = $ this ->container -> getParameter ( ' web_profiler.debug_toolbar.position ' ) ;
184
+ $ position = $ this ->toolbarPosition ;
176
185
}
177
186
178
187
$ url = null ;
179
188
try {
180
- $ url = $ this ->container -> get ( ' router ' ) ->generate ('_profiler ' , array ('token ' => $ token ));
189
+ $ url = $ this ->generator ->generate ('_profiler ' , array ('token ' => $ token ));
181
190
} catch (\Exception $ e ) {
182
191
// the profiler is not enabled
183
192
}
184
193
185
- return $ this ->container -> get ( ' templating ' )-> renderResponse ( ' WebProfilerBundle: Profiler: toolbar.html.twig ' , array (
194
+ return new Response ( $ this ->twig -> render ( ' @WebProfiler/ Profiler/ toolbar.html.twig ' , array (
186
195
'position ' => $ position ,
187
196
'profile ' => $ profile ,
188
197
'templates ' => $ this ->getTemplateManager ()->getTemplates ($ profile ),
189
198
'profiler_url ' => $ url ,
190
199
'token ' => $ token ,
191
- ));
200
+ ))) ;
192
201
}
193
202
194
203
/**
@@ -200,8 +209,7 @@ public function toolbarAction(Request $request, $token, $position = null)
200
209
*/
201
210
public function searchBarAction (Request $ request )
202
211
{
203
- $ profiler = $ this ->container ->get ('profiler ' );
204
- $ profiler ->disable ();
212
+ $ this ->profiler ->disable ();
205
213
206
214
if (null === $ session = $ request ->getSession ()) {
207
215
$ ip =
@@ -217,13 +225,13 @@ public function searchBarAction(Request $request)
217
225
$ token = $ session ->get ('_profiler_search_token ' );
218
226
}
219
227
220
- return $ this ->container -> get ( ' templating ' )-> renderResponse ( ' WebProfilerBundle: Profiler: search.html.twig ' , array (
228
+ return new Response ( $ this ->twig -> render ( ' @WebProfiler/ Profiler/ search.html.twig ' , array (
221
229
'token ' => $ token ,
222
230
'ip ' => $ ip ,
223
231
'method ' => $ method ,
224
232
'url ' => $ url ,
225
233
'limit ' => $ limit ,
226
- ));
234
+ ))) ;
227
235
}
228
236
229
237
/**
@@ -236,26 +244,25 @@ public function searchBarAction(Request $request)
236
244
*/
237
245
public function searchResultsAction (Request $ request , $ token )
238
246
{
239
- $ profiler = $ this ->container ->get ('profiler ' );
240
- $ profiler ->disable ();
247
+ $ this ->profiler ->disable ();
241
248
242
- $ profile = $ profiler ->loadProfile ($ token );
249
+ $ profile = $ this -> profiler ->loadProfile ($ token );
243
250
244
251
$ ip = $ request ->query ->get ('ip ' );
245
252
$ method = $ request ->query ->get ('method ' );
246
253
$ url = $ request ->query ->get ('url ' );
247
254
$ limit = $ request ->query ->get ('limit ' );
248
255
249
- return $ this ->container -> get ( ' templating ' )-> renderResponse ( ' WebProfilerBundle: Profiler: results.html.twig ' , array (
256
+ return new Response ( $ this ->twig -> render ( ' @WebProfiler/ Profiler/ results.html.twig ' , array (
250
257
'token ' => $ token ,
251
258
'profile ' => $ profile ,
252
- 'tokens ' => $ profiler ->find ($ ip , $ url , $ limit , $ method ),
259
+ 'tokens ' => $ this -> profiler ->find ($ ip , $ url , $ limit , $ method ),
253
260
'ip ' => $ ip ,
254
261
'method ' => $ method ,
255
262
'url ' => $ url ,
256
263
'limit ' => $ limit ,
257
264
'panel ' => null ,
258
- ));
265
+ ))) ;
259
266
}
260
267
261
268
/**
@@ -267,8 +274,7 @@ public function searchResultsAction(Request $request, $token)
267
274
*/
268
275
public function searchAction (Request $ request )
269
276
{
270
- $ profiler = $ this ->container ->get ('profiler ' );
271
- $ profiler ->disable ();
277
+ $ this ->profiler ->disable ();
272
278
273
279
$ ip = preg_replace ('/[^:\d\.]/ ' , '' , $ request ->query ->get ('ip ' ));
274
280
$ method = $ request ->query ->get ('method ' );
@@ -285,12 +291,12 @@ public function searchAction(Request $request)
285
291
}
286
292
287
293
if (!empty ($ token )) {
288
- return new RedirectResponse ($ this ->container -> get ( ' router ' ) ->generate ('_profiler ' , array ('token ' => $ token )));
294
+ return new RedirectResponse ($ this ->generator ->generate ('_profiler ' , array ('token ' => $ token )));
289
295
}
290
296
291
- $ tokens = $ profiler ->find ($ ip , $ url , $ limit , $ method );
297
+ $ tokens = $ this -> profiler ->find ($ ip , $ url , $ limit , $ method );
292
298
293
- return new RedirectResponse ($ this ->container -> get ( ' router ' ) ->generate ('_profiler_search_results ' , array (
299
+ return new RedirectResponse ($ this ->generator ->generate ('_profiler_search_results ' , array (
294
300
'token ' => $ tokens ? $ tokens [0 ]['token ' ] : 'empty ' ,
295
301
'ip ' => $ ip ,
296
302
'method ' => $ method ,
@@ -306,8 +312,7 @@ public function searchAction(Request $request)
306
312
*/
307
313
public function phpinfoAction ()
308
314
{
309
- $ profiler = $ this ->container ->get ('profiler ' );
310
- $ profiler ->disable ();
315
+ $ this ->profiler ->disable ();
311
316
312
317
ob_start ();
313
318
phpinfo ();
@@ -319,11 +324,7 @@ public function phpinfoAction()
319
324
protected function getTemplateManager ()
320
325
{
321
326
if (null === $ this ->templateManager ) {
322
- $ this ->templateManager = new TemplateManager (
323
- $ this ->container ->get ('profiler ' ),
324
- $ this ->container ->get ('twig ' ),
325
- $ this ->container ->getParameter ('data_collector.templates ' )
326
- );
327
+ $ this ->templateManager = new TemplateManager ($ this ->profiler , $ this ->twig , $ this ->templates );
327
328
}
328
329
329
330
return $ this ->templateManager ;
0 commit comments