@@ -162,7 +162,30 @@ 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 ([
175
+ [
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 ;
188
+
166
189
}
167
190
}
168
191
@@ -281,4 +304,44 @@ private function varToString($var): string
281
304
282
305
return (string ) $ var ;
283
306
}
307
+
308
+ private function parseControllerDefinition (callable $ controller ): ?array
309
+ {
310
+ if (is_string ($ controller ) && false !== strpos ($ controller , ':: ' )) {
311
+ $ controller = explode (':: ' , $ controller );
312
+ }
313
+
314
+ if (is_array ($ controller )) {
315
+ try {
316
+ $ r = new \ReflectionMethod ($ controller [0 ], $ controller [1 ]);
317
+
318
+ return array (
319
+ 'file ' => $ r ->getFileName (),
320
+ 'line ' => $ r ->getStartLine (),
321
+ );
322
+ } catch (\ReflectionException $ e ) {
323
+ return null ;
324
+ }
325
+ }
326
+
327
+ if ($ controller instanceof \Closure) {
328
+ $ r = new \ReflectionFunction ($ controller );
329
+
330
+ return array (
331
+ 'file ' => $ r ->getFileName (),
332
+ 'line ' => $ r ->getStartLine (),
333
+ );
334
+ }
335
+
336
+ if (is_object ($ controller )) {
337
+ $ r = new \ReflectionClass ($ controller );
338
+
339
+ return array (
340
+ 'file ' => $ r ->getFileName (),
341
+ 'line ' => $ r ->getStartLine (),
342
+ );
343
+ }
344
+
345
+ return null ;
346
+ }
284
347
}
0 commit comments