@@ -276,10 +276,69 @@ public function __toString()
276
276
$ reflection ->setAccessible (true );
277
277
$ reflection ->setValue ($ exception , $ this ->trace );
278
278
279
- return 'deprecation triggered by ' .$ this ->originatingClass ().':: ' .$ this ->originatingMethod ().': ' .
279
+ $ string = 'deprecation triggered by ' .$ this ->originatingClass ().':: ' .$ this ->originatingMethod ().': ' .
280
280
"\n" .$ this ->message .
281
281
"\nStack trace: " .
282
- "\n" .str_replace (' ' .getcwd ().\DIRECTORY_SEPARATOR , ' ' , $ exception ->getTraceAsString ()).
283
282
"\n" ;
283
+ foreach ($ exception ->getTrace () as $ index => $ line ) {
284
+ $ package = $ this ->getPackageFromLine ($ line );
285
+ $ string .= sprintf (
286
+ '#%d [%s] %s%s::%s ' ,
287
+ $ index ,
288
+ $ package ,
289
+ isset ($ line ['file ' ]) ? sprintf ('%s(%d): ' , $ line ['file ' ], $ line ['line ' ]): '' ,
290
+ $ line ['class ' ],
291
+ $ line ['function ' ]
292
+ );
293
+ $ textArgs = [];
294
+ foreach ($ line ['args ' ] as $ arg ) {
295
+ switch (gettype ($ arg )) {
296
+ case 'integer ' :
297
+ $ textArgs [] = $ arg ;
298
+ break ;
299
+ case 'string ' :
300
+ $ argString = "' " ;
301
+ $ substr = substr ($ arg , 0 , 15 );
302
+ $ argString .= str_replace ("\n" , '\n ' , $ substr );
303
+ if (strlen ($ substr ) !== strlen ($ string )) {
304
+ $ argString .= '… ' ;
305
+ }
306
+ $ textArgs [] = "$ argString' " ;
307
+ break ;
308
+ case 'array ' :
309
+ $ textArgs [] = 'Array ' ;
310
+ break ;
311
+ case 'object ' :
312
+ $ textArgs [] = sprintf ('Object(%s) ' , get_class ($ arg ));
313
+ break ;
314
+ case 'boolean ' :
315
+ $ textArgs [] = $ arg ?'true ' :'false ' ;
316
+ break ;
317
+
318
+ default :
319
+ $ textArgs [] = gettype ($ arg );
320
+ break ;
321
+ }
322
+ }
323
+ $ string .= sprintf ('(%s) ' , implode (', ' , $ textArgs ));
324
+ $ string .= PHP_EOL ;
325
+ }
326
+
327
+ return $ string ;
328
+ }
329
+
330
+ private function getPackageFromLine (array $ line )
331
+ {
332
+ if (!isset ($ line ['file ' ])) {
333
+ return 'internal function ' ;
334
+ }
335
+ if (!$ this ->pathOriginatesFromVendor ($ line ['file ' ])) {
336
+ return 'source code ' ;
337
+ }
338
+ try {
339
+ return $ this ->getPackage ($ line ['file ' ]);
340
+ } catch (\RuntimeException $ e ) {
341
+ return 'unknown ' ;
342
+ }
284
343
}
285
344
}
0 commit comments