19
19
use Symfony \Component \Console \Output \OutputInterface ;
20
20
use Symfony \Component \Console \Style \SymfonyStyle ;
21
21
use Symfony \Component \Finder \Finder ;
22
+ use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
22
23
use Twig \Environment ;
23
24
use Twig \Loader \ChainLoader ;
24
25
use Twig \Loader \FilesystemLoader ;
@@ -38,8 +39,9 @@ class DebugCommand extends Command
38
39
private $ twigDefaultPath ;
39
40
private $ rootDir ;
40
41
private $ filesystemLoaders ;
42
+ private $ fileLinkFormatter ;
41
43
42
- public function __construct (Environment $ twig , string $ projectDir = null , array $ bundlesMetadata = [], string $ twigDefaultPath = null , string $ rootDir = null )
44
+ public function __construct (Environment $ twig , string $ projectDir = null , array $ bundlesMetadata = [], string $ twigDefaultPath = null , string $ rootDir = null , FileLinkFormatter $ fileLinkFormatter = null )
43
45
{
44
46
parent ::__construct ();
45
47
@@ -48,6 +50,7 @@ public function __construct(Environment $twig, string $projectDir = null, array
48
50
$ this ->bundlesMetadata = $ bundlesMetadata ;
49
51
$ this ->twigDefaultPath = $ twigDefaultPath ;
50
52
$ this ->rootDir = $ rootDir ;
53
+ $ this ->fileLinkFormatter = $ fileLinkFormatter ;
51
54
}
52
55
53
56
protected function configure ()
@@ -105,16 +108,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
105
108
106
109
private function displayPathsText (SymfonyStyle $ io , string $ name )
107
110
{
108
- $ files = $ this ->findTemplateFiles ($ name );
111
+ $ file = new \ ArrayIterator ( $ this ->findTemplateFiles ($ name) );
109
112
$ paths = $ this ->getLoaderPaths ($ name );
110
113
111
114
$ io ->section ('Matched File ' );
112
- if ($ files ) {
113
- $ io ->success (array_shift ($ files ));
115
+ if ($ file ->valid ()) {
116
+ if ($ fileLink = $ this ->getFileLink ($ file ->key ())) {
117
+ $ io ->block ($ file ->current (), 'OK ' , sprintf ('fg=black;bg=green;href=%s ' , $ fileLink ), ' ' , true );
118
+ } else {
119
+ $ io ->success ($ file ->current ());
120
+ }
121
+ $ file ->next ();
114
122
115
- if ($ files ) {
123
+ if ($ file -> valid () ) {
116
124
$ io ->section ('Overridden Files ' );
117
- $ io ->listing ($ files );
125
+ do {
126
+ if ($ fileLink = $ this ->getFileLink ($ file ->key ())) {
127
+ $ io ->text (sprintf ('* <href=%s>%s</> ' , $ fileLink , $ file ->current ()));
128
+ } else {
129
+ $ io ->text (sprintf ('* %s ' , $ file ->current ()));
130
+ }
131
+ $ file ->next ();
132
+ } while ($ file ->valid ());
118
133
}
119
134
} else {
120
135
$ alternatives = [];
@@ -453,9 +468,9 @@ private function findTemplateFiles(string $name): array
453
468
454
469
if (is_file ($ filename )) {
455
470
if (false !== $ realpath = realpath ($ filename )) {
456
- $ files [] = $ this ->getRelativePath ($ realpath );
471
+ $ files [$ realpath ] = $ this ->getRelativePath ($ realpath );
457
472
} else {
458
- $ files [] = $ this ->getRelativePath ($ filename );
473
+ $ files [$ filename ] = $ this ->getRelativePath ($ filename );
459
474
}
460
475
}
461
476
}
@@ -563,4 +578,13 @@ private function getFilesystemLoaders(): array
563
578
564
579
return $ this ->filesystemLoaders ;
565
580
}
581
+
582
+ private function getFileLink (string $ absolutePath ): string
583
+ {
584
+ if (null === $ this ->fileLinkFormatter ) {
585
+ return '' ;
586
+ }
587
+
588
+ return (string ) $ this ->fileLinkFormatter ->format ($ absolutePath , 1 );
589
+ }
566
590
}
0 commit comments