Skip to content

Commit ee4a4ff

Browse files
[DoctrineBridge] fix setting default mapping type to attribute/annotation on php 8/7 respectively
1 parent ed2e5a8 commit ee4a4ff

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\DependencyInjection;
1313

14+
use Symfony\Component\Config\Resource\GlobResource;
1415
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
@@ -88,6 +89,25 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
8889
if (!$mappingConfig) {
8990
continue;
9091
}
92+
} elseif (!$mappingConfig['type'] && \PHP_VERSION_ID < 80000) {
93+
$mappingConfig['type'] = 'annotation';
94+
} elseif (!$mappingConfig['type']) {
95+
$mappingConfig['type'] = 'attribute';
96+
97+
$glob = new GlobResource($mappingConfig['dir'], '*', true);
98+
$container->addResource($glob);
99+
100+
foreach ($glob as $file) {
101+
$content = file_get_contents($file);
102+
103+
if (preg_match('/^#\[.*Entity\b/m', $content)) {
104+
break;
105+
}
106+
if (preg_match('/^ \* @.*Entity\b/m', $content)) {
107+
$mappingConfig['type'] = 'annotation';
108+
break;
109+
}
110+
}
91111
}
92112

93113
$this->assertValidMappingConfiguration($mappingConfig, $objectManager['name']);

0 commit comments

Comments
 (0)