@@ -33,6 +33,7 @@ public function __construct(
3333 private string $ namespacePrefix ,
3434 ?PhpCompatUtil $ phpCompatUtil = null ,
3535 private ?TemplateComponentGenerator $ templateComponentGenerator = null ,
36+ private array $ templatesFolders = [],
3637 ) {
3738 $ this ->twigHelper = new GeneratorTwigHelper ($ fileManager );
3839 $ this ->namespacePrefix = trim ($ namespacePrefix , '\\' );
@@ -299,11 +300,7 @@ private function addOperation(string $targetPath, string $templateName, array $v
299300
300301 $ templatePath = $ templateName ;
301302 if (!file_exists ($ templatePath )) {
302- $ templatePath = \sprintf ('%s/templates/%s ' , \dirname (__DIR__ ), $ templateName );
303-
304- if (!file_exists ($ templatePath )) {
305- $ templatePath = $ this ->getTemplateFromLegacySkeletonPath ($ templateName );
306- }
303+ $ templatePath = $ this ->getTemplatePath ($ templatePath );
307304
308305 if (!file_exists ($ templatePath )) {
309306 throw new \Exception (\sprintf ('Cannot find template "%s" in the templates/ dir. ' , $ templateName ));
@@ -316,6 +313,25 @@ private function addOperation(string $targetPath, string $templateName, array $v
316313 ];
317314 }
318315
316+ private function getTemplatePath (string $ templateName ): string
317+ {
318+ foreach ($ this ->templatesFolders as $ folder ) {
319+ $ templatePath = \sprintf ('%s/%s ' , $ folder , $ templateName );
320+
321+ if ($ this ->fileManager ->fileExists ($ templatePath )) {
322+ return $ templatePath ;
323+ }
324+ }
325+
326+ $ templatePath = \sprintf ('%s/templates/%s ' , \dirname (__DIR__ ), $ templateName );
327+
328+ if (!file_exists ($ templatePath )) {
329+ return $ this ->getTemplateFromLegacySkeletonPath ($ templateName );
330+ }
331+
332+ return $ templatePath ;
333+ }
334+
319335 /**
320336 * @legacy - Remove when public generate methods become "internal" to MakerBundle in v2
321337 */
0 commit comments