Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<argument /> <!-- root namespace -->
<argument>null</argument> <!-- PhpCompatUtil -->
<argument type="service" id="maker.template_component_generator" />
<argument /> <!-- templates_folders -->
</service>

<service id="maker.entity_class_generator" class="Symfony\Bundle\MakerBundle\Doctrine\EntityClassGenerator">
Expand Down
26 changes: 21 additions & 5 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\');
Expand Down Expand Up @@ -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));
Expand All @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions src/MakerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
;
}
Expand All @@ -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')
Expand Down
Loading