@@ -122,48 +122,34 @@ public function collect(Request $request, Response $response, \Exception $except
122
122
}
123
123
124
124
if (isset ($ this ->controllers [$ request ])) {
125
- $ controller = $ this ->controllers [$ request ];
126
- if (is_array ($ controller )) {
127
- try {
128
- $ r = new \ReflectionMethod ($ controller [0 ], $ controller [1 ]);
129
- $ this ->data ['controller ' ] = array (
130
- 'class ' => is_object ($ controller [0 ]) ? get_class ($ controller [0 ]) : $ controller [0 ],
131
- 'method ' => $ controller [1 ],
132
- 'file ' => $ r ->getFileName (),
133
- 'line ' => $ r ->getStartLine (),
134
- );
135
- } catch (\ReflectionException $ e ) {
136
- if (is_callable ($ controller )) {
137
- // using __call or __callStatic
138
- $ this ->data ['controller ' ] = array (
139
- 'class ' => is_object ($ controller [0 ]) ? get_class ($ controller [0 ]) : $ controller [0 ],
140
- 'method ' => $ controller [1 ],
141
- 'file ' => 'n/a ' ,
142
- 'line ' => 'n/a ' ,
143
- );
144
- }
145
- }
146
- } elseif ($ controller instanceof \Closure) {
147
- $ r = new \ReflectionFunction ($ controller );
148
- $ this ->data ['controller ' ] = array (
149
- 'class ' => $ r ->getName (),
150
- 'method ' => null ,
151
- 'file ' => $ r ->getFileName (),
152
- 'line ' => $ r ->getStartLine (),
153
- );
154
- } elseif (is_object ($ controller )) {
155
- $ r = new \ReflectionClass ($ controller );
156
- $ this ->data ['controller ' ] = array (
157
- 'class ' => $ r ->getName (),
158
- 'method ' => null ,
159
- 'file ' => $ r ->getFileName (),
160
- 'line ' => $ r ->getStartLine (),
161
- );
162
- } else {
163
- $ this ->data ['controller ' ] = (string ) $ controller ?: 'n/a ' ;
164
- }
125
+ $ this ->data ['controller ' ] = $ this ->parseController ($ this ->controllers [$ request ]);
165
126
unset($ this ->controllers [$ request ]);
166
127
}
128
+
129
+ if ($ parentRequestAttributes = $ request ->attributes ->get ('_forwarded ' )) {
130
+ if ($ parentRequestAttributes instanceof ParameterBag) {
131
+ $ parentRequestAttributes ->set ('_forward_token ' , $ response ->headers ->get ('x-debug-token ' ));
132
+ }
133
+ }
134
+
135
+ if ($ request ->attributes ->has ('_forward_controller ' )) {
136
+ $ this ->data ['forward ' ] = array (
137
+ 'token ' => $ request ->attributes ->get ('_forward_token ' ),
138
+ 'controller ' => $ request ->attributes ->get ('_forward_controller ' ),
139
+ );
140
+ }
141
+
142
+ if ($ request ->hasSession () && $ request ->getSession ()->has ('sf_redirect ' )) {
143
+ $ this ->data ['redirect ' ] = $ request ->getSession ()->get ('sf_redirect ' );
144
+ $ request ->getSession ()->remove ('sf_redirect ' );
145
+ }
146
+
147
+ if ($ request ->hasSession () && $ response ->isRedirect ()) {
148
+ $ request ->getSession ()->set ('sf_redirect ' , array (
149
+ 'token ' => $ response ->headers ->get ('x-debug-token ' ),
150
+ 'route ' => $ request ->attributes ->get ('_route ' , 'n/a ' ),
151
+ ));
152
+ }
167
153
}
168
154
169
155
public function getPathInfo ()
@@ -276,18 +262,41 @@ public function getRouteParams()
276
262
}
277
263
278
264
/**
279
- * Gets the controller.
265
+ * Gets the parsed controller.
280
266
*
281
- * @return string The controller as a string
267
+ * @return array|string The controller as a string or array of data
268
+ * with keys 'class', 'method', 'file' and 'line'
282
269
*/
283
270
public function getController ()
284
271
{
285
272
return $ this ->data ['controller ' ];
286
273
}
287
274
275
+ /**
276
+ * Gets the parsed forward controller.
277
+ *
278
+ * @return array|bool An array with keys 'token' the forward profile token, and
279
+ * 'controller' the parsed forward controller, false otherwise
280
+ */
281
+ public function getForward ()
282
+ {
283
+ return isset ($ this ->data ['forward ' ]) ? $ this ->data ['forward ' ] : false ;
284
+ }
285
+
286
+ public function getRedirect ()
287
+ {
288
+ return isset ($ this ->data ['redirect ' ]) ? $ this ->data ['redirect ' ] : false ;
289
+ }
290
+
288
291
public function onKernelController (FilterControllerEvent $ event )
289
292
{
290
293
$ this ->controllers [$ event ->getRequest ()] = $ event ->getController ();
294
+
295
+ if ($ parentRequestAttributes = $ event ->getRequest ()->attributes ->get ('_forwarded ' )) {
296
+ if ($ parentRequestAttributes instanceof ParameterBag) {
297
+ $ parentRequestAttributes ->set ('_forward_controller ' , $ this ->parseController ($ event ->getController ()));
298
+ }
299
+ }
291
300
}
292
301
293
302
public static function getSubscribedEvents ()
@@ -339,4 +348,61 @@ private function getCookieHeader($name, $value, $expires, $path, $domain, $secur
339
348
340
349
return $ cookie ;
341
350
}
351
+
352
+ /**
353
+ * Parse a controller.
354
+ *
355
+ * @param mixed $controller The controller to parse
356
+ *
357
+ * @return array|string An array of controller data or a simple string
358
+ */
359
+ private function parseController ($ controller )
360
+ {
361
+ if (is_array ($ controller )) {
362
+ try {
363
+ $ r = new \ReflectionMethod ($ controller [0 ], $ controller [1 ]);
364
+
365
+ return array (
366
+ 'class ' => is_object ($ controller [0 ]) ? get_class ($ controller [0 ]) : $ controller [0 ],
367
+ 'method ' => $ controller [1 ],
368
+ 'file ' => $ r ->getFileName (),
369
+ 'line ' => $ r ->getStartLine (),
370
+ );
371
+ } catch (\ReflectionException $ e ) {
372
+ if (is_callable ($ controller )) {
373
+ // using __call or __callStatic
374
+ return array (
375
+ 'class ' => is_object ($ controller [0 ]) ? get_class ($ controller [0 ]) : $ controller [0 ],
376
+ 'method ' => $ controller [1 ],
377
+ 'file ' => 'n/a ' ,
378
+ 'line ' => 'n/a ' ,
379
+ );
380
+ }
381
+ }
382
+ }
383
+
384
+ if ($ controller instanceof \Closure) {
385
+ $ r = new \ReflectionFunction ($ controller );
386
+
387
+ return array (
388
+ 'class ' => $ r ->getName (),
389
+ 'method ' => null ,
390
+ 'file ' => $ r ->getFileName (),
391
+ 'line ' => $ r ->getStartLine (),
392
+ );
393
+ }
394
+
395
+ if (is_object ($ controller )) {
396
+ $ r = new \ReflectionClass ($ controller );
397
+
398
+ return array (
399
+ 'class ' => $ r ->getName (),
400
+ 'method ' => null ,
401
+ 'file ' => $ r ->getFileName (),
402
+ 'line ' => $ r ->getStartLine (),
403
+ );
404
+ }
405
+
406
+ return (string ) $ controller ?: 'n/a ' ;
407
+ }
342
408
}
0 commit comments