@@ -162,7 +162,29 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST)
162
162
if (null === $ response ) {
163
163
$ msg .= ' Did you forget to add a return statement somewhere in your controller? ' ;
164
164
}
165
- throw new \LogicException ($ msg );
165
+
166
+ $ e = new \LogicException ($ msg );
167
+
168
+ if (!$ controllerDefinition = $ this ->parseControllerDefinition ($ controller )) {
169
+ throw $ e ;
170
+ }
171
+
172
+ $ r = new \ReflectionProperty (\Exception::class, 'trace ' );
173
+ $ r ->setAccessible (true );
174
+ $ r ->setValue ($ e , array_merge (array (
175
+ array (
176
+ 'line ' => $ e ->getLine (),
177
+ 'file ' => $ e ->getFile (),
178
+ ),
179
+ ), $ e ->getTrace ()));
180
+ $ r = new \ReflectionProperty (\Exception::class, 'file ' );
181
+ $ r ->setAccessible (true );
182
+ $ r ->setValue ($ e , $ controllerDefinition ['file ' ]);
183
+ $ r = new \ReflectionProperty (\Exception::class, 'line ' );
184
+ $ r ->setAccessible (true );
185
+ $ r ->setValue ($ e , $ controllerDefinition ['line ' ]);
186
+
187
+ throw $ e ;
166
188
}
167
189
}
168
190
@@ -281,4 +303,44 @@ private function varToString($var): string
281
303
282
304
return (string ) $ var ;
283
305
}
306
+
307
+ private function parseControllerDefinition (callable $ controller ): ?array
308
+ {
309
+ if (is_string ($ controller ) && false !== strpos ($ controller , ':: ' )) {
310
+ $ controller = explode (':: ' , $ controller );
311
+ }
312
+
313
+ if (is_array ($ controller )) {
314
+ try {
315
+ $ r = new \ReflectionMethod ($ controller [0 ], $ controller [1 ]);
316
+
317
+ return array (
318
+ 'file ' => $ r ->getFileName (),
319
+ 'line ' => $ r ->getStartLine (),
320
+ );
321
+ } catch (\ReflectionException $ e ) {
322
+ return null ;
323
+ }
324
+ }
325
+
326
+ if ($ controller instanceof \Closure) {
327
+ $ r = new \ReflectionFunction ($ controller );
328
+
329
+ return array (
330
+ 'file ' => $ r ->getFileName (),
331
+ 'line ' => $ r ->getStartLine (),
332
+ );
333
+ }
334
+
335
+ if (is_object ($ controller )) {
336
+ $ r = new \ReflectionClass ($ controller );
337
+
338
+ return array (
339
+ 'file ' => $ r ->getFileName (),
340
+ 'line ' => $ r ->getStartLine (),
341
+ );
342
+ }
343
+
344
+ return null ;
345
+ }
284
346
}
0 commit comments