@@ -32,14 +32,18 @@ class DebugCommand extends Command
32
32
private $ twig ;
33
33
private $ projectDir ;
34
34
private $ bundlesMetadata ;
35
+ private $ twigDefaultPath ;
36
+ private $ rootDir ;
35
37
36
- public function __construct (Environment $ twig , string $ projectDir = null , array $ bundlesMetadata = array ())
38
+ public function __construct (Environment $ twig , string $ projectDir = null , array $ bundlesMetadata = array (), string $ twigDefaultPath = null , string $ rootDir = null )
37
39
{
38
40
parent ::__construct ();
39
41
40
42
$ this ->twig = $ twig ;
41
43
$ this ->projectDir = $ projectDir ;
42
44
$ this ->bundlesMetadata = $ bundlesMetadata ;
45
+ $ this ->twigDefaultPath = $ twigDefaultPath ;
46
+ $ this ->rootDir = $ rootDir ;
43
47
}
44
48
45
49
protected function configure ()
@@ -85,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
85
89
$ data ['tests ' ] = array_keys ($ data ['tests ' ]);
86
90
$ data ['loader_paths ' ] = $ this ->getLoaderPaths ();
87
91
$ io ->writeln (json_encode ($ data ));
88
- $ this ->displayAlternatives ($ this ->findWrongBundleOverrides ($ data [ ' loader_paths ' ] ), $ io );
92
+ $ this ->displayAlternatives ($ this ->findWrongBundleOverrides (), $ io );
89
93
90
94
return 0 ;
91
95
}
@@ -111,8 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
111
115
}
112
116
113
117
$ rows = array ();
114
- $ loaderPaths = $ this ->getLoaderPaths ();
115
- foreach ($ loaderPaths as $ namespace => $ paths ) {
118
+ foreach ($ this ->getLoaderPaths () as $ namespace => $ paths ) {
116
119
if (count ($ paths ) > 1 ) {
117
120
$ rows [] = array ('' , '' );
118
121
}
@@ -127,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
127
130
array_pop ($ rows );
128
131
$ io ->section ('Loader Paths ' );
129
132
$ io ->table (array ('Namespace ' , 'Paths ' ), $ rows );
130
- $ this ->displayAlternatives ($ this ->findWrongBundleOverrides ($ loaderPaths ), $ io );
133
+ $ this ->displayAlternatives ($ this ->findWrongBundleOverrides (), $ io );
131
134
132
135
return 0 ;
133
136
}
@@ -248,25 +251,45 @@ private function getPrettyMetadata($type, $entity)
248
251
}
249
252
}
250
253
251
- private function findWrongBundleOverrides ($ loaderPaths )
254
+ private function findWrongBundleOverrides (): array
252
255
{
253
256
$ alternatives = array ();
254
- $ paths = array_unique ($ loaderPaths ['(None) ' ]);
255
257
$ bundleNames = array ();
256
- foreach ($ paths as $ path ) {
257
- $ relativePath = $ path .'/bundles/ ' ;
258
- if (file_exists ($ dir = $ this ->projectDir .'/ ' .$ relativePath )) {
259
- $ folders = glob ($ dir .'* ' , GLOB_ONLYDIR );
260
- $ bundleNames = array_reduce ($ folders , function ($ carry , $ absolutePath ) use ($ relativePath ) {
258
+
259
+ if ($ this ->rootDir ) {
260
+ $ folders = glob ($ this ->rootDir .'/Resources/*/views ' , GLOB_ONLYDIR );
261
+ $ relativePath = ltrim (substr ($ this ->rootDir .'/Resources/ ' , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
262
+ $ bundleNames = array_reduce (
263
+ $ folders ,
264
+ function ($ carry , $ absolutePath ) use ($ relativePath ) {
265
+ if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
266
+ $ name = basename (\dirname ($ absolutePath ));
267
+ $ path = $ relativePath .$ name ;
268
+ $ carry [$ name ] = $ path ;
269
+ }
270
+
271
+ return $ carry ;
272
+ },
273
+ $ bundleNames
274
+ );
275
+ }
276
+
277
+ if ($ this ->twigDefaultPath ) {
278
+ $ folders = glob ($ this ->twigDefaultPath .'/bundles/* ' , GLOB_ONLYDIR );
279
+ $ relativePath = ltrim (substr ($ this ->twigDefaultPath .'/bundles ' , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
280
+ $ bundleNames = array_reduce (
281
+ $ folders ,
282
+ function ($ carry , $ absolutePath ) use ($ relativePath ) {
261
283
if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
262
284
$ path = ltrim (substr ($ absolutePath , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
263
285
$ name = ltrim (substr ($ path , \strlen ($ relativePath )), DIRECTORY_SEPARATOR );
264
286
$ carry [$ name ] = $ path ;
265
287
}
266
288
267
289
return $ carry ;
268
- }, $ bundleNames );
269
- }
290
+ },
291
+ $ bundleNames
292
+ );
270
293
}
271
294
272
295
if (\count ($ bundleNames )) {
@@ -289,7 +312,7 @@ private function findWrongBundleOverrides($loaderPaths)
289
312
return $ alternatives ;
290
313
}
291
314
292
- private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io )
315
+ private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io ): void
293
316
{
294
317
foreach ($ wrongBundles as $ path => $ alternatives ) {
295
318
$ message = sprintf ('Path "%s" not matching any bundle found ' , $ path );
0 commit comments