@@ -32,14 +32,18 @@ class DebugCommand extends Command
3232 private $ twig ;
3333 private $ projectDir ;
3434 private $ bundlesMetadata ;
35+ private $ twigDefaultPath ;
36+ private $ rootDir ;
3537
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 , string $ rootDir )
3739 {
3840 parent ::__construct ();
3941
4042 $ this ->twig = $ twig ;
4143 $ this ->projectDir = $ projectDir ;
4244 $ this ->bundlesMetadata = $ bundlesMetadata ;
45+ $ this ->twigDefaultPath = $ twigDefaultPath ;
46+ $ this ->rootDir = $ rootDir ;
4347 }
4448
4549 protected function configure ()
@@ -85,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8589 $ data ['tests ' ] = array_keys ($ data ['tests ' ]);
8690 $ data ['loader_paths ' ] = $ this ->getLoaderPaths ();
8791 $ io ->writeln (json_encode ($ data ));
88- $ this ->displayAlternatives ($ this ->findWrongBundleOverrides ($ data [ ' loader_paths ' ] ), $ io );
92+ $ this ->displayAlternatives ($ this ->findWrongBundleOverrides (), $ io );
8993
9094 return 0 ;
9195 }
@@ -111,8 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
111115 }
112116
113117 $ rows = array ();
114- $ loaderPaths = $ this ->getLoaderPaths ();
115- foreach ($ loaderPaths as $ namespace => $ paths ) {
118+ foreach ($ this ->getLoaderPaths () as $ namespace => $ paths ) {
116119 if (count ($ paths ) > 1 ) {
117120 $ rows [] = array ('' , '' );
118121 }
@@ -127,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
127130 array_pop ($ rows );
128131 $ io ->section ('Loader Paths ' );
129132 $ io ->table (array ('Namespace ' , 'Paths ' ), $ rows );
130- $ this ->displayAlternatives ($ this ->findWrongBundleOverrides ($ loaderPaths ), $ io );
133+ $ this ->displayAlternatives ($ this ->findWrongBundleOverrides (), $ io );
131134
132135 return 0 ;
133136 }
@@ -248,26 +251,42 @@ private function getPrettyMetadata($type, $entity)
248251 }
249252 }
250253
251- private function findWrongBundleOverrides ($ loaderPaths )
254+ private function findWrongBundleOverrides (): array
252255 {
253256 $ alternatives = array ();
254- $ paths = array_unique ($ loaderPaths ['(None) ' ]);
255257 $ 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 ) {
261- if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
262- $ path = ltrim (substr ($ absolutePath , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
263- $ name = ltrim (substr ($ path , \strlen ($ relativePath )), DIRECTORY_SEPARATOR );
264- $ carry [$ name ] = $ path ;
265- }
266258
267- return $ carry ;
268- }, $ bundleNames );
269- }
270- }
259+ $ folders = glob ($ this ->rootDir .'/Resources/*/views ' , GLOB_ONLYDIR );
260+ $ relativePath = ltrim (substr ($ this ->rootDir .'/Resources/ ' , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
261+ $ bundleNames = array_reduce (
262+ $ folders ,
263+ function ($ carry , $ absolutePath ) use ($ relativePath ) {
264+ if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
265+ $ name = basename (dirname ($ absolutePath ));
266+ $ path = $ relativePath .$ name ;
267+ $ carry [$ name ] = $ path ;
268+ }
269+
270+ return $ carry ;
271+ },
272+ $ bundleNames
273+ );
274+
275+ $ folders = glob ($ this ->twigDefaultPath .'/bundles/* ' , GLOB_ONLYDIR );
276+ $ relativePath = ltrim (substr ($ this ->twigDefaultPath .'/bundles ' , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
277+ $ bundleNames = array_reduce (
402E
code>278+ $ folders ,
279+ function ($ carry , $ absolutePath ) use ($ relativePath ) {
280+ if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
281+ $ path = ltrim (substr ($ absolutePath , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
282+ $ name = ltrim (substr ($ path , \strlen ($ relativePath )), DIRECTORY_SEPARATOR );
283+ $ carry [$ name ] = $ path ;
284+ }
285+
286+ return $ carry ;
287+ },
288+ $ bundleNames
289+ );
271290
272291 if (\count ($ bundleNames )) {
273292 $ loadedBundles = $ this ->bundlesMetadata ;
@@ -289,7 +308,7 @@ private function findWrongBundleOverrides($loaderPaths)
289308 return $ alternatives ;
290309 }
291310
292- private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io )
311+ private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io ): void
293312 {
294313 foreach ($ wrongBundles as $ path => $ alternatives ) {
295314 $ message = sprintf ('Path "%s" not matching any bundle found ' , $ path );
0 commit comments