Skip to content

Commit 354772f

Browse files
TheArrowRichardalanpoulain
authored andcommitted
feat: add yaml support for doctrine resolve entity
1 parent 669b975 commit 354772f

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ parameters:
4949
checkIsGoodRelations: boolean,
5050
header: ?string,
5151
namespaces: array{prefix: ?string, entity: string, enum: string, interface: string},
52-
doctrine: array{useCollection: boolean, resolveTargetEntityConfigPath: ?string, inheritanceAttributes: array<string, (int|bool|null|string|string[]|string[][]|\Nette\PhpGenerator\Literal)[]>},
52+
doctrine: array{useCollection: boolean, resolveTargetEntityConfigPath: ?string, resolveTargetEntityConfigType: 'XML'|'yaml', inheritanceAttributes: array<string, (int|bool|null|string|string[]|string[][]|\Nette\PhpGenerator\Literal)[]>},
5353
validator: array{assertType: boolean},
5454
author: false|string,
5555
fieldVisibility: string,

src/TypesGenerator.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,16 @@ public function generate(array $config): void
281281
$dir = \dirname($file);
282282
$this->filesystem->mkdir($dir);
283283

284+
$fileType = $config['doctrine']['resolveTargetEntityConfigType'];
285+
286+
$mappingTemplateFile = 'doctrine.xml.twig';
287+
if ('yaml' === $fileType) {
288+
$mappingTemplateFile = 'doctrine.yaml.twig';
289+
}
290+
284291
file_put_contents(
285292
$file,
286-
$this->twig->render('doctrine.xml.twig', ['mappings' => $interfaceMappings])
293+
$this->twig->render($mappingTemplateFile, ['mappings' => $interfaceMappings])
287294
);
288295

289296
$generatedFiles[] = $file;

src/TypesGeneratorConfiguration.php

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static function ($rdf) {
109109
->children()
110110
->booleanNode('useCollection')->defaultTrue()->info('Use Doctrine\'s ArrayCollection instead of standard arrays')->end()
111111
->scalarNode('resolveTargetEntityConfigPath')->defaultNull()->info('The Resolve Target Entity Listener config file path')->end()
112+
->enumNode('resolveTargetEntityConfigType')->defaultValue('XML')->values(['XML', 'yaml'])->info('The Resolve Target Entity Listener config file type')->end()
112113
->arrayNode('inheritanceAttributes')
113114
->info('Doctrine inheritance attributes (if set, no other attributes are generated)')
114115
->prototype('variable')->end()

templates/doctrine.yaml.twig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
doctrine:
2+
orm:
3+
resolve_target_entities:
4+
{% for interface, class in mappings %}
5+
{{ interface }}: {{ class }}
6+
{% endfor %}

tests/Command/DumpConfigurationTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ interface: App\Model # Example: App\Model
101101
# The Resolve Target Entity Listener config file path
102102
resolveTargetEntityConfigPath: null
103103
104+
# The Resolve Target Entity Listener config file type
105+
resolveTargetEntityConfigType: XML # One of "XML"; "yaml"
106+
104107
# Doctrine inheritance attributes (if set, no other attributes are generated)
105108
inheritanceAttributes: []
106109

0 commit comments

Comments
 (0)