12
12
namespace Symfony \Bridge \Twig \Command ;
13
13
14
14
use Symfony \Component \Console \Command \Command ;
15
+ use Symfony \Component \Console \Helper \TableSeparator ;
15
16
use Symfony \Component \Console \Input \InputArgument ;
16
17
use Symfony \Component \Console \Input \InputOption ;
17
18
use Symfony \Component \Console \Input \InputInterface ;
@@ -30,11 +31,13 @@ class DebugCommand extends Command
30
31
protected static $ defaultName = 'debug:twig ' ;
31
32
32
33
private $ twig ;
34
+ private $ projectDir ;
33
35
34
36
/**
35
37
* @param Environment $twig
38
+ * @param string|null $projectDir
36
39
*/
37
- public function __construct ($ twig = null )
40
+ public function __construct ($ twig = null , $ projectDir = null )
38
41
{
39
42
if (!$ twig instanceof Environment) {
40
43
@trigger_error (sprintf ('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead. ' , __METHOD__ ), E_USER_DEPRECATED );
@@ -47,6 +50,7 @@ public function __construct($twig = null)
47
50
parent ::__construct ();
48
51
49
52
$ this ->twig = $ twig ;
53
+ $ this ->projectDir = $ projectDir ;
50
54
}
51
55
52
56
public function setTwigEnvironment (Environment $ twig )
@@ -147,14 +151,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
147
151
$ io ->listing ($ items );
148
152
}
149
153
150
- $ list = array ();
154
+ $ rows = array ();
151
155
foreach ($ this ->getLoaderPaths () as $ namespace => $ paths ) {
152
- $ list = array_merge ($ list , array_map (function ($ path ) use ($ namespace ) {
153
- return $ namespace .($ namespace ? ': ' : '' ).$ path ;
154
- }, $ paths ));
156
+ foreach ($ paths as $ path ) {
157
+ $ rows [] = array ($ namespace , '* ' .$ path );
158
+ $ namespace = '' ;
159
+ }
160
+ $ rows [] = new TableSeparator ();
155
161
}
162
+ array_pop ($ rows );
156
163
$ io ->section ('Loader Paths ' );
157
- $ io ->listing ( $ list );
164
+ $ io ->table ( array ( ' Namespace ' , ' Paths ' ), $ rows );
158
165
159
166
return 0 ;
160
167
}
@@ -165,16 +172,26 @@ private function getLoaderPaths()
165
172
return array ();
166
173
}
167
174
168
- $ paths = array ();
175
+ $ loaderPaths = array ();
169
176
foreach ($ loader ->getNamespaces () as $ namespace ) {
177
+ $ paths = array_map (function ($ path ) use ($ namespace ) {
178
+ if (null !== $ this ->projectDir && 0 === strpos ($ path , $ this ->projectDir )) {
179
+ $ path = ltrim (substr ($ path , strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
180
+ }
181
+
182
+ return $ path ;
183
+ }, $ loader ->getPaths ($ namespace ));
184
+
170
185
if (FilesystemLoader::MAIN_NAMESPACE === $ namespace ) {
171
- $ paths [ '' ] = $ loader -> getPaths ( $ namespace ) ;
186
+ $ namespace = ' (None) ' ;
172
187
} else {
173
- $ paths [ '@ ' .$ namespace] = $ loader -> getPaths ( $ namespace ) ;
188
+ $ namespace = '@ ' .$ namespace ;
174
189
}
190
+
191
+ $ loaderPaths [$ namespace ] = $ paths ;
175
192
}
176
193
177
- return $ paths ;
194
+ return $ loaderPaths ;
178
195
}
179
196
180
197
private function getMetadata ($ type , $ entity )
0 commit comments