Skip to content

feat: Add YAML support for doctrine resolve entity. #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2021
Merged
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
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ parameters:
checkIsGoodRelations: boolean,
header: ?string,
namespaces: array{prefix: ?string, entity: string, enum: string, interface: string},
doctrine: array{useCollection: boolean, resolveTargetEntityConfigPath: ?string, inheritanceAttributes: array<string, (int|bool|null|string|string[]|string[][]|\Nette\PhpGenerator\Literal)[]>},
doctrine: array{useCollection: boolean, resolveTargetEntityConfigPath: ?string, resolveTargetEntityConfigType: 'XML'|'yaml', inheritanceAttributes: array<string, (int|bool|null|string|string[]|string[][]|\Nette\PhpGenerator\Literal)[]>},
validator: array{assertType: boolean},
author: false|string,
fieldVisibility: string,
Expand Down
9 changes: 8 additions & 1 deletion src/TypesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,16 @@ public function generate(array $config): void
$dir = \dirname($file);
$this->filesystem->mkdir($dir);

$fileType = $config['doctrine']['resolveTargetEntityConfigType'];

$mappingTemplateFile = 'doctrine.xml.twig';
if ('yaml' === $fileType) {
$mappingTemplateFile = 'doctrine.yaml.twig';
}

file_put_contents(
$file,
$this->twig->render('doctrine.xml.twig', ['mappings' => $interfaceMappings])
$this->twig->render($mappingTemplateFile, ['mappings' => $interfaceMappings])
);

$generatedFiles[] = $file;
Expand Down
1 change: 1 addition & 0 deletions src/TypesGeneratorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static function ($rdf) {
->children()
->booleanNode('useCollection')->defaultTrue()->info('Use Doctrine\'s ArrayCollection instead of standard arrays')->end()
->scalarNode('resolveTargetEntityConfigPath')->defaultNull()->info('The Resolve Target Entity Listener config file path')->end()
->enumNode('resolveTargetEntityConfigType')->defaultValue('XML')->values(['XML', 'yaml'])->info('The Resolve Target Entity Listener config file type')->end()
->arrayNode('inheritanceAttributes')
->info('Doctrine inheritance attributes (if set, no other attributes are generated)')
->prototype('variable')->end()
Expand Down
6 changes: 6 additions & 0 deletions templates/doctrine.yaml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
doctrine:
orm:
resolve_target_entities:
{% for interface, class in mappings %}
{{ interface }}: {{ class }}
{% endfor %}
3 changes: 3 additions & 0 deletions tests/Command/DumpConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ interface: App\Model # Example: App\Model
# The Resolve Target Entity Listener config file path
resolveTargetEntityConfigPath: null

# The Resolve Target Entity Listener config file type
resolveTargetEntityConfigType: XML # One of "XML"; "yaml"

# Doctrine inheritance attributes (if set, no other attributes are generated)
inheritanceAttributes: []

Expand Down