@@ -240,11 +240,11 @@ private function renderActions(\Throwable $ex): array
240
240
/**
241
241
* Returns syntax highlighted source code.
242
242
*/
243
- public static function highlightFile (string $ file , int $ line , int $ lines = 15 , array $ vars = []): ?string
243
+ public static function highlightFile (string $ file , int $ line , int $ lines = 15 , array $ vars = [], array $ keysToHide = [] ): ?string
244
244
{
245
245
$ source = @file_get_contents ($ file ); // @ file may not exist
246
246
if ($ source ) {
247
- $ source = static ::highlightPhp ($ source , $ line , $ lines , $ vars );
247
+ $ source = static ::highlightPhp ($ source , $ line , $ lines , $ vars, $ keysToHide );
248
248
if ($ editor = Helpers::editorUri ($ file , $ line )) {
249
249
$ source = substr_replace ($ source , ' data-tracy-href=" ' . Helpers::escapeHtml ($ editor ) . '" ' , 4 , 0 );
250
250
}
@@ -256,7 +256,7 @@ public static function highlightFile(string $file, int $line, int $lines = 15, a
256
256
/**
257
257
* Returns syntax highlighted source code.
258
258
*/
259
- public static function highlightPhp (string $ source , int $ line , int $ lines = 15 , array $ vars = []): string
259
+ public static function highlightPhp (string $ source , int $ line , int $ lines = 15 , array $ vars = [], array $ keysToHide = [] ): string
260
260
{
261
261
if (function_exists ('ini_set ' )) {
262
262
ini_set ('highlight.comment ' , '#998; font-style: italic ' );
@@ -273,12 +273,15 @@ public static function highlightPhp(string $source, int $line, int $lines = 15,
273
273
$ out .= static ::highlightLine ($ source , $ line , $ lines );
274
274
275
275
if ($ vars ) {
276
- $ out = preg_replace_callback ('#">\$(\w+)( )?</span># ' , function (array $ m ) use ($ vars ): string {
277
- return array_key_exists ($ m [1 ], $ vars )
278
- ? '" title=" '
279
- . str_replace ('" ' , '" ' , trim (strip_tags (Dumper::toHtml ($ vars [$ m [1 ]], [Dumper::DEPTH => 1 ]))))
280
- . $ m [0 ]
281
- : $ m [0 ];
276
+ $ out = preg_replace_callback ('#">\$(\w+)( )?</span># ' , function (array $ m ) use ($ vars , $ keysToHide ): string {
277
+ if (array_key_exists ($ m [1 ], $ vars )) {
278
+ $ dump = Dumper::toHtml ($ vars [$ m [1 ]], [
279
+ Dumper::DEPTH => 1 ,
280
+ Dumper::KEYS_TO_HIDE => $ keysToHide ,
281
+ ]);
282
+ return '" title=" ' . str_replace ('" ' , '" ' , trim (strip_tags ($ dump ))) . $ m [0 ];
283
+ }
284
+ return $ m [0 ];
282
285
}, $ out );
283
286
}
284
287
0 commit comments