@@ -206,7 +206,6 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
206
206
$ f ['file ' ] = substr ($ f ['file ' ], 0 , -\strlen ($ match [0 ]));
207
207
$ f ['line ' ] = (int ) $ match [1 ];
208
208
}
209
- $ caller = isset ($ f ['function ' ]) ? sprintf ('in %s() on line %d ' , (isset ($ f ['class ' ]) ? $ f ['class ' ].$ f ['type ' ] : '' ).$ f ['function ' ], $ f ['line ' ]) : null ;
210
209
$ src = $ f ['line ' ];
211
210
$ srcKey = $ f ['file ' ];
212
211
$ ellipsis = new LinkStub ($ srcKey , 0 );
@@ -226,13 +225,13 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
226
225
$ templatePath = null ;
227
226
}
228
227
if ($ templateSrc ) {
229
- $ src = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext , $ caller , 'twig ' , $ templatePath );
228
+ $ src = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext , 'twig ' , $ templatePath, $ f );
230
229
$ srcKey = ($ templatePath ?: $ template ->getTemplateName ()).': ' .$ templateInfo [$ f ['line ' ]];
231
230
}
232
231
}
233
232
}
234
233
if ($ srcKey == $ f ['file ' ]) {
235
- $ src = self ::extractSource (file_get_contents ($ f ['file ' ]), $ f ['line ' ], self ::$ srcContext , $ caller , 'php ' , $ f ['file ' ]);
234
+ $ src = self ::extractSource (file_get_contents ($ f ['file ' ]), $ f ['line ' ], self ::$ srcContext , 'php ' , $ f ['file ' ], $ f );
236
235
$ srcKey .= ': ' .$ f ['line ' ];
237
236
if ($ ellipsis ) {
238
237
$ ellipsis += 1 + \strlen ($ f ['line ' ]);
@@ -308,7 +307,7 @@ private static function traceUnshift(array &$trace, ?string $class, string $file
308
307
]);
309
308
}
310
309
311
- private static function extractSource (string $ srcLines , int $ line , int $ srcContext , ? string $ title , string $ lang , string $ file = null ): EnumStub
310
+ private static function extractSource (string $ srcLines , int $ line , int $ srcContext , string $ lang , ? string $ file, array $ frame ): EnumStub
312
311
{
313
312
$ srcLines = explode ("\n" , $ srcLines );
314
313
$ src = [];
@@ -317,7 +316,33 @@ private static function extractSource(string $srcLines, int $line, int $srcConte
317
316
$ src [] = (isset ($ srcLines [$ i ]) ? $ srcLines [$ i ] : '' )."\n" ;
318
317
}
319
318
320
- $ srcLines = [];
319
+
320
+ if ($ frame ['function ' ] ?? false ) {
321
+ $ stub = new CutStub (new \stdClass ());
322
+ $ stub ->class = (isset ($ frame ['class ' ]) ? $ frame ['class ' ].$ frame ['type ' ] : '' ).$ frame ['function ' ];
323
+ $ stub ->type = Stub::TYPE_OBJECT ;
324
+ $ stub ->attr ['cut_hash ' ] = true ;
325
+ $ stub ->attr ['file ' ] = $ frame ['file ' ];
326
+ $ stub ->attr ['line ' ] = $ frame ['line ' ];
327
+
328
+ try {
329
+ $ caller = isset ($ frame ['class ' ]) ? new \ReflectionMethod ($ frame ['class ' ], $ frame ['function ' ]) : new \ReflectionFunction ($ frame ['function ' ]);
330
+ $ stub ->class .= ReflectionCaster::getSignature (ReflectionCaster::castFunctionAbstract ($ caller , [], $ stub , true , Caster::EXCLUDE_VERBOSE ));
331
+
332
+ if ($ f = $ caller ->getFileName ()) {
333
+ $ stub ->attr ['file ' ] = $ f ;
334
+ $ stub ->attr ['line ' ] = $ caller ->getStartLine ();
335
+ }
336
+ } catch (\ReflectionException $ e ) {
337
+ // ignore fake class/function
338
+ }
339
+
340
+ $ srcLines = ["\0~separator= \0" => $ stub ];
341
+ } else {
342
+ $ stub = null ;
343
+ $ srcLines = [];
344
+ }
345
+
321
346
$ ltrim = 0 ;
322
347
do {
323
348
$ pad = null ;
@@ -344,7 +369,7 @@ private static function extractSource(string $srcLines, int $line, int $srcConte
344
369
if ($ i !== $ srcContext ) {
345
370
$ c = new ConstStub ('default ' , $ c );
346
371
} else {
347
- $ c = new ConstStub ($ c , $ title );
372
+ $ c = new ConstStub ($ c , $ stub ? ' in ' . $ stub -> class : '' );
348
373
if (null !== $ file ) {
349
374
$ c ->attr ['file ' ] = $ file ;
350
375
$ c ->attr ['line ' ] = $ line ;
0 commit comments