diff --git a/config/services.xml b/config/services.xml
index 5fbc0439b..f1984ae0d 100644
--- a/config/services.xml
+++ b/config/services.xml
@@ -57,6 +57,7 @@
null
+
diff --git a/src/Generator.php b/src/Generator.php
index 221899d07..892f991ec 100644
--- a/src/Generator.php
+++ b/src/Generator.php
@@ -33,6 +33,7 @@ public function __construct(
private string $namespacePrefix,
?PhpCompatUtil $phpCompatUtil = null,
private ?TemplateComponentGenerator $templateComponentGenerator = null,
+ private array $templatesFolders = [],
) {
$this->twigHelper = new GeneratorTwigHelper($fileManager);
$this->namespacePrefix = trim($namespacePrefix, '\\');
@@ -299,11 +300,7 @@ private function addOperation(string $targetPath, string $templateName, array $v
$templatePath = $templateName;
if (!file_exists($templatePath)) {
- $templatePath = \sprintf('%s/templates/%s', \dirname(__DIR__), $templateName);
-
- if (!file_exists($templatePath)) {
- $templatePath = $this->getTemplateFromLegacySkeletonPath($templateName);
- }
+ $templatePath = $this->getTemplatePath($templatePath);
if (!file_exists($templatePath)) {
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
];
}
+ private function getTemplatePath(string $templateName): string
+ {
+ foreach ($this->templatesFolders as $folder) {
+ $templatePath = \sprintf('%s/%s', $folder, $templateName);
+
+ if ($this->fileManager->fileExists($templatePath)) {
+ return $templatePath;
+ }
+ }
+
+ $templatePath = \sprintf('%s/templates/%s', \dirname(__DIR__), $templateName);
+
+ if (!file_exists($templatePath)) {
+ return $this->getTemplateFromLegacySkeletonPath($templateName);
+ }
+
+ return $templatePath;
+ }
+
/**
* @legacy - Remove when public generate methods become "internal" to MakerBundle in v2
*/
diff --git a/src/MakerBundle.php b/src/MakerBundle.php
index 42516aec8..bf3b9e7c3 100644
--- a/src/MakerBundle.php
+++ b/src/MakerBundle.php
@@ -35,6 +35,10 @@ public function configure(DefinitionConfigurator $definition): void
->scalarNode('root_namespace')->defaultValue('App')->end()
->booleanNode('generate_final_classes')->defaultTrue()->end()
->booleanNode('generate_final_entities')->defaultFalse()->end()
+ ->arrayNode('templates_folders')
+ ->defaultValue([])
+ ->prototype('scalar')->end()
+ ->end()
->end()
;
}
@@ -51,6 +55,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->arg(0, $rootNamespace)
->get('maker.generator')
->arg(1, $rootNamespace)
+ ->arg(4, $config['templates_folders'])
->get('maker.doctrine_helper')
->arg(0, \sprintf('%s\\Entity', $rootNamespace))
->get('maker.template_component_generator')