Skip to content

Commit 7d50513

Browse files
Merge branch '5.2' into 5.3
* 5.2: [Cache] clarify RedisStore::evaluate() [Messenger] Fixed BC layer for RedeliveryStamp [DoctrineBridge] fix setting default mapping type to attribute/annotation on php 8/7 respectively do not render the same label id attribute twice make AbstractDataCollector extend DataCollector to reduce boilerplate
2 parents 10c882f + f0ba020 commit 7d50513

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)