@@ -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 = null , string $ rootDir = null )
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 );
<
8000
/td>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,25 +251,45 @@ 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 ) {
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 ) {
261283 if (null !== $ this ->projectDir && 0 === strpos ($ absolutePath , $ this ->projectDir )) {
262284 $ path = ltrim (substr ($ absolutePath , \strlen ($ this ->projectDir )), DIRECTORY_SEPARATOR );
263285 $ name = ltrim (substr ($ path , \strlen ($ relativePath )), DIRECTORY_SEPARATOR );
264286 $ carry [$ name ] = $ path ;
265287 }
266288
267289 return $ carry ;
268- }, $ bundleNames );
269- }
290+ },
291+ $ bundleNames
292+ );
270293 }
271294
272295 if (\count ($ bundleNames )) {
@@ -289,7 +312,7 @@ private function findWrongBundleOverrides($loaderPaths)
289312 return $ alternatives ;
290313 }
291314
292- private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io )
315+ private function displayAlternatives (array $ wrongBundles , SymfonyStyle $ io ): void
293316 {
294317 foreach ($ wrongBundles as $ path => $ alternatives ) {
295318 $ message = sprintf ('Path "%s" not matching any bundle found ' , $ path );
0 commit comments