11
11
12
12
namespace Symfony \Component \VarDumper \Command \Descriptor ;
13
13
14
+ use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
14
15
use Symfony \Component \Console \Input \ArrayInput ;
15
16
use Symfony \Component \Console \Output \OutputInterface ;
16
17
use Symfony \Component \Console \Style \SymfonyStyle ;
@@ -28,10 +29,12 @@ class CliDescriptor implements DumpDescriptorInterface
28
29
{
29
30
private $ dumper ;
30
31
private $ lastIdentifier ;
32
+ private $ supportsHref ;
31
33
32
34
public function __construct (CliDumper $ dumper )
33
35
{
34
36
$ this ->dumper = $ dumper ;
37
+ $ this ->supportsHref = method_exists (OutputFormatterStyle::class, 'setHref ' );
35
38
}
36
39
37
40
public function describe (OutputInterface $ output , Data $ data , array $ context , int $ clientId ): void
@@ -62,15 +65,19 @@ public function describe(OutputInterface $output, Data $data, array $context, in
62
65
63
66
if (isset ($ context ['source ' ])) {
64
67
$ source = $ context ['source ' ];
65
- $ rows [] = array ('source ' , sprintf ('%s on line %d ' , $ source ['name ' ], $ source ['line ' ]));
68
+ $ sourceInfo = sprintf ('%s on line %d ' , $ source ['name ' ], $ source ['line ' ]);
69
+ $ fileLink = $ source ['file_link ' ] ?? null ;
70
+ if ($ this ->supportsHref && $ fileLink ) {
71
+ $ sourceInfo = sprintf ('<href=%s>%s</> ' , $ fileLink , $ sourceInfo );
72
+ }
73
+ $ rows [] = array ('source ' , $ sourceInfo );
66
74
$ file = $ source ['file_relative ' ] ?? $ source ['file ' ];
67
75
$ rows [] = array ('file ' , $ file );
68
- $ fileLink = $ source ['file_link ' ] ?? null ;
69
76
}
70
77
71
78
$ io ->table (array (), $ rows );
72
79
73
- if (isset ($ fileLink )) {
80
+ if (! $ this -> supportsHref && isset ($ fileLink )) {
74
81
$ io ->writeln (array ('<info>Open source in your IDE/browser:</info> ' , $ fileLink ));
75
82
$ io ->newLine ();
76
83
}
0 commit comments