Skip to content

Commit ff3657d

Browse files
committed
bug #43917 Allow autodetecting mapping type for any object (franmomu)
This PR was merged into the 5.4 branch. Discussion ---------- Allow autodetecting mapping type for any object | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> This PR would allow to auto detect the mapping type for Documents or other types Commits ------- 2555167975 Allow autodetecting mapping type for any object
2 parents e294c53 + 024b1c9 commit ff3657d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,15 @@ private function detectMappingType(string $directory, ContainerBuilder $containe
301301
$glob = new GlobResource($directory, '*', true);
302302
$container->addResource($glob);
303303

304+
$quotedMappingObjectName = preg_quote($this->getMappingObjectDefaultName(), '/');
305+
304306
foreach ($glob as $file) {
305307
$content = file_get_contents($file);
306308

307-
if (preg_match('/^#\[.*Entity\b/m', $content)) {
309+
if (preg_match('/^#\[.*'.$quotedMappingObjectName.'\b/m', $content)) {
308310
break;
309311
}
310-
if (preg_match('/^ \* @.*Entity\b/m', $content)) {
312+
if (preg_match('/^ \* @.*'.$quotedMappingObjectName.'\b/m', $content)) {
311313
$type = 'annotation';
312314
break;
313315
}

Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ protected function setUp(): void
4949
->willReturnCallback(function ($name) {
5050
return 'doctrine.orm.'.$name;
5151
});
52+
53+
$this->extension
54+
->method('getMappingObjectDefaultName')
55+
->willReturn('Entity');
5256
}
5357

5458
public function testFixManagersAutoMappingsWithTwoAutomappings()

0 commit comments

Comments
 (0)