19
19
use Symfony \Component \Console \Style \SymfonyStyle ;
20
20
use Symfony \Component \ErrorRenderer \ErrorRenderer \ErrorRendererInterface ;
21
21
use Symfony \Component \ErrorRenderer \Exception \FlattenException ;
22
+ use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
22
23
23
24
/**
24
25
* A console command for retrieving information about error renderers.
@@ -32,13 +33,15 @@ class DebugCommand extends Command
32
33
protected static $ defaultName = 'debug:error-renderer ' ;
33
34
34
35
private $ renderers ;
36
+ private $ fileLinkFormatter ;
35
37
36
38
/**
37
39
* @param ErrorRendererInterface[] $renderers
38
40
*/
39
- public function __construct (array $ renderers )
41
+ public function __construct (array $ renderers, FileLinkFormatter $ fileLinkFormatter = null )
40
42
{
41
43
$ this ->renderers = $ renderers ;
44
+ $ this ->fileLinkFormatter = $ fileLinkFormatter ;
42
45
43
46
parent ::__construct ();
44
47
}
@@ -84,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
84
87
} else {
85
88
$ tableRows = [];
86
89
foreach ($ renderers as $ format => $ renderer ) {
87
- $ tableRows [] = [sprintf ('<fg=cyan>%s</fg=cyan> ' , $ format ), \get_class ($ renderer )];
90
+ $ tableRows [] = [sprintf ('<fg=cyan>%s</fg=cyan> ' , $ format ), $ this -> formatClassLink ( \get_class ($ renderer) )];
88
91
}
89
92
90
93
$ io ->title ('Error Renderers ' );
@@ -93,4 +96,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
93
96
$ io ->table (['Format ' , 'Class ' ], $ tableRows );
94
97
}
95
98
}
99
+
100
+ private function formatClassLink (string $ class ): string
101
+ {
102
+ if ('' === $ fileLink = $ this ->getFileLink ($ class )) {
103
+ return $ class ;
104
+ }
105
+
106
+ return sprintf ('<href=%s>%s</> ' , $ fileLink , $ class );
107
+ }
108
+
109
+ private function getFileLink (string $ class ): string
110
+ {
111
+ if (null === $ this ->fileLinkFormatter ) {
112
+ return '' ;
113
+ }
114
+
115
+ try {
116
+ $ r = new \ReflectionClass ($ class );
117
+ } catch (\ReflectionException $ e ) {
118
+ return '' ;
119
+ }
120
+
121
+ return $ this ->fileLinkFormatter ->format ($ r ->getFileName (), $ r ->getStartLine ());
122
+ }
96
123
}
0 commit comments