24
24
*/
25
25
class CliDumper extends AbstractDumper
26
26
{
27
+ const DUMP_DUMP_LOCATION = 16 ;
28
+
27
29
public static $ defaultColors ;
28
30
public static $ defaultOutput = 'php://stdout ' ;
29
31
@@ -88,6 +90,8 @@ public function __construct($output = null, string $charset = null, int $flags =
88
90
]);
89
91
}
90
92
93
+ $ this ->handlesHrefGracefully = 'JetBrains-JediTerm ' !== getenv ('TERMINAL_EMULATOR ' );
94
+
91
95
$ this ->displayOptions ['fileLinkFormat ' ] = ini_get ('xdebug.file_link_format ' ) ?: get_cfg_var ('xdebug.file_link_format ' ) ?: 'file://%f ' ;
92
96
}
93
97
@@ -131,37 +135,6 @@ public function setDisplayOptions(array $displayOptions)
131
135
$ this ->displayOptions = $ displayOptions + $ this ->displayOptions ;
132
136
}
133
137
134
- /**
135
- * {@inheritdoc}
136
- */
137
- public function dump (Data $ data , $ output = null , array $ extraDisplayOptions = [])
138
- {
139
- $ this ->extraDisplayOptions = $ extraDisplayOptions ;
140
- $ result = parent ::dump ($ data , $ output );
141
-
142
- return $ result ;
143
- }
144
-
145
- /**
146
- * Configures file of the dump call function.
147
- *
148
- * @param string $file File path issued from debug_backtrace
149
- */
150
- public function setFile (string $ file )
151
- {
152
- $ this ->attr ['file ' ] = $ file ;
153
- }
154
-
155
- /**
156
- * Configures line of the dump call function.
157
- *
158
- * @param int $line File line issued from debug_backtrace
159
- */
160
- public function setLine (int $ line )
161
- {
162
- $ this ->attr ['line ' ] = $ line ;
163
- }
164
-
165
138
/**
166
139
* {@inheritdoc}
167
140
*/
@@ -334,7 +307,7 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
334
307
$ prefix = substr ($ prefix , 0 , -1 );
335
308
}
336
309
337
- $ this ->line .= $ prefix ;
310
+ $ this ->line .= $ prefix . $ this -> dumpLocation ( $ cursor , $ attr ) ;
338
311
339
312
if ($ hasChild ) {
340
313
$ this ->dumpLine ($ cursor ->depth );
@@ -470,10 +443,6 @@ protected function style($style, $value, $attr = [])
470
443
$ this ->colors = $ this ->supportsColors ();
471
444
}
472
445
473
- if (null === $ this ->handlesHrefGracefully ) {
474
- $ this ->handlesHrefGracefully = 'JetBrains-JediTerm ' !== getenv ('TERMINAL_EMULATOR ' );
475
- }
476
-
477
446
if (isset ($ attr ['ellipsis ' ], $ attr ['ellipsis-type ' ])) {
478
447
$ prefix = substr ($ value , 0 , -$ attr ['ellipsis ' ]);
479
448
if ('cli ' === \PHP_SAPI && 'path ' === $ attr ['ellipsis-type ' ] && isset ($ _SERVER [$ pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD ' : 'PWD ' ]) && 0 === strpos ($ prefix , $ _SERVER [$ pwd ])) {
@@ -487,47 +456,31 @@ protected function style($style, $value, $attr = [])
487
456
}
488
457
489
458
$ value = $ this ->style ('default ' , $ prefix ).$ this ->style ($ style , $ value );
490
-
491
- goto href;
492
- }
493
-
494
- $ map = static ::$ controlCharsMap ;
495
- $ startCchr = $ this ->colors ? "\033[m \033[ {$ this ->styles ['default ' ]}m " : '' ;
496
- $ endCchr = $ this ->colors ? "\033[m \033[ {$ this ->styles [$ style ]}m " : '' ;
497
- $ value = preg_replace_callback (static ::$ controlCharsRx , function ($ c ) use ($ map , $ startCchr , $ endCchr ) {
498
- $ s = $ startCchr ;
499
- $ c = $ c [$ i = 0 ];
500
- do {
501
- $ s .= isset ($ map [$ c [$ i ]]) ? $ map [$ c [$ i ]] : sprintf ('\x%02X ' , \ord ($ c [$ i ]));
502
- } while (isset ($ c [++$ i ]));
503
-
504
- return $ s .$ endCchr ;
505
- }, $ value , -1 , $ cchrCount );
506
-
507
- if ($ this ->colors ) {
508
- if ($ cchrCount && "\033" === $ value [0 ]) {
509
- $ value = substr ($ value , \strlen ($ startCchr ));
510
- } else {
511
- $ value = "\033[ {$ this ->styles [$ style ]}m " .$ value ;
512
- }
513
- if ($ cchrCount && $ endCchr === substr ($ value , -\strlen ($ endCchr ))) {
514
- $ value = substr ($ value , 0 , -\strlen ($ endCchr ));
515
- } else {
516
- $ value .= "\033[ {$ this ->styles ['default ' ]}m " ;
517
- }
518
- }
519
-
520
- href:
521
- if ($ this ->colors && $ this ->handlesHrefGracefully ) {
522
- if (isset ($ attr ['file ' ]) && $ href = $ this ->getSourceLink ($ attr ['file ' ], isset ($ attr ['line ' ]) ? $ attr ['line ' ] : 0 )) {
523
- if ('note ' === $ style ) {
524
- $ value .= "\033]8;; {$ href }\033\\^ \033]8;; \033\\" ;
459
+ } else {
460
+ $ map = static ::$ controlCharsMap ;
461
+ $ startCchr = $ this ->colors ? "\033[m \033[ {$ this ->styles ['default ' ]}m " : '' ;
462
+ $ endCchr = $ this ->colors ? "\033[m \033[ {$ this ->styles [$ style ]}m " : '' ;
463
+ $ value = preg_replace_callback (static ::$ controlCharsRx , function ($ c ) use ($ map , $ startCchr , $ endCchr ) {
464
+ $ s = $ startCchr ;
465
+ $ c = $ c [$ i = 0 ];
466
+ do {
467
+ $ s .= isset ($ map [$ c [$ i ]]) ? $ map [$ c [$ i ]] : sprintf ('\x%02X ' , \ord ($ c [$ i ]));
468
+ } while (isset ($ c [++$ i ]));
469
+
470
+ return $ s .$ endCchr ;
471
+ }, $ value , -1 , $ cchrCount );
472
+
473
+ if ($ this ->colors ) {
474
+ if ($ cchrCount && "\033" === $ value [0 ]) {
475
+ $ value = substr ($ value , \strlen ($ startCchr ));
525
476
} else {
526
- $ attr ['href ' ] = $ href ;
477
+ $ value = "\033[ {$ this ->styles [$ style ]}m " .$ value ;
478
+ }
479
+ if ($ cchrCount && $ endCchr === substr ($ value , -\strlen ($ endCchr ))) {
480
+ $ value = substr ($ value , 0 , -\strlen ($ endCchr ));
481
+ } else {
482
+ $ value .= "\033[ {$ this ->styles ['default ' ]}m " ;
527
483
}
528
- }
529
- if (isset ($ attr ['href ' ])) {
530
- $ value .= " \033]8;; {$ attr ['href ' ]}\033\\[^] \033]8;; \033\\" ;
531
484
}
532
485
}
533
486
@@ -668,10 +621,29 @@ private function isWindowsTrueColor()
668
621
return $ result ;
669
622
}
670
623
671
- private function getSourceLink ($ file , $ line )
624
+ /**
625
+ * Return the substring with the dump() function file location to get displayed with a small caret after
626
+ * an hash.
627
+ *
628
+ * @param Cursor $cursor
629
+ * @param array $attr
630
+ * @return string
631
+ */
632
+ private function dumpLocation (Cursor $ cursor , $ attr = []) :string
633
+ {
634
+ if ($ this ->handlesHrefGracefully && $ cursor ->depth === 0 && isset ($ attr ['file ' ]) && $ href = $ this ->getSourceLink ($ attr ['file ' ], $ attr ['line ' ])) {
635
+ $ color = $ this ->colors ? "\033" : '' ;
636
+
637
+ return " {$ color }]8;; {$ href }{$ color }\\[^] {$ color }]8;; {$ color }\\" ;
638
+ }
639
+
640
+ return '' ;
641
+ }
642
+
643
+ private function getSourceLink ($ file , $ lineNumber )
672
644
{
673
645
if ($ fmt = $ this ->displayOptions ['fileLinkFormat ' ]) {
674
- return \is_string ($ fmt ) ? strtr ($ fmt , ['%f ' => $ file , '%l ' => $ line ]) : ($ fmt ->format ($ file , $ line ) ?: 'file:// ' .$ file );
646
+ return \is_string ($ fmt ) ? strtr ($ fmt , ['%f ' => $ file , '%l ' => $ lineNumber ]) : ($ fmt ->format ($ file , $ lineNumber ) ?: 'file:// ' .$ file );
675
647
}
676
648
677
649
return false ;
0 commit comments