Skip to content

Commit f7920f8

Browse files
[7.0] Cleanup legacy code paths
1 parent 34f1787 commit f7920f8

File tree

2 files changed

+8
-73
lines changed

2 files changed

+8
-73
lines changed

DependencyInjection/AbstractDoctrineExtension.php

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

1212
namespace Symfony\Bridge\Doctrine\DependencyInjection;
1313

14-
use Symfony\Component\Config\Resource\GlobResource;
1514
use Symfony\Component\DependencyInjection\Alias;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Definition;
@@ -91,8 +90,8 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
9190
if (!$mappingConfig) {
9291
continue;
9392
}
94-
} elseif (!$mappingConfig['type']) {
95-
$mappingConfig['type'] = $this->detectMappingType($mappingConfig['dir'], $container);
93+
} else {
94+
$mappingConfig['type'] ??= 'attribute';
9695
}
9796

9897
$this->assertValidMappingConfiguration($mappingConfig, $objectManager['name']);
@@ -154,7 +153,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
154153
}
155154

156155
if (!$bundleConfig['dir']) {
157-
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
156+
if (\in_array($bundleConfig['type'], ['staticphp', 'attribute'])) {
158157
$bundleConfig['dir'] = $bundleClassDir.'/'.$this->getMappingObjectDefaultName();
159158
} else {
160159
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
@@ -187,21 +186,8 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder
187186
if ($container->hasDefinition($mappingService)) {
188187
$mappingDriverDef = $container->getDefinition($mappingService);
189188
$args = $mappingDriverDef->getArguments();
190-
if ('annotation' == $driverType) {
191-
$args[1] = array_merge(array_values($driverPaths), $args[1]);
192-
} else {
193-
$args[0] = array_merge(array_values($driverPaths), $args[0]);
194-
}
189+
$args[0] = array_merge(array_values($driverPaths), $args[0]);
195190
$mappingDriverDef->setArguments($args);
196-
} elseif ('attribute' === $driverType) {
197-
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
198-
array_values($driverPaths),
199-
]);
200-
} elseif ('annotation' == $driverType) {
201-
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
202-
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
203-
array_values($driverPaths),
204-
]);
205191
} else {
206192
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
207193
array_values($driverPaths),
@@ -237,8 +223,8 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string
237223
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
238224
}
239225

240-
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp', 'attribute'])) {
241-
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
226+
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'php', 'staticphp', 'attribute'])) {
227+
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
242228
}
243229
}
244230

@@ -264,8 +250,8 @@ protected function detectMetadataDriver(string $dir, ContainerBuilder $container
264250
}
265251
$container->fileExists($resource, false);
266252

267-
if ($container->fileExists($discoveryPath = $dir.'/'.$this->getMappingObjectDefaultName(), false)) {
268-
return $this->detectMappingType($discoveryPath, $container);
253+
if ($container->fileExists($dir.'/'.$this->getMappingObjectDefaultName(), false)) {
254+
return 'attribute';
269255
}
270256

271257
return null;
@@ -275,41 +261,6 @@ protected function detectMetadataDriver(string $dir, ContainerBuilder $container
275261
return $driver;
276262
}
277263

278-
/**
279-
* Detects what mapping type to use for the supplied directory.
280-
*
281-
* @return string A mapping type 'attribute' or 'annotation'
282-
*/
283-
private function detectMappingType(string $directory, ContainerBuilder $container): string
284-
{
285-
$type = 'attribute';
286-
287-
$glob = new GlobResource($directory, '*', true);
288-
$container->addResource($glob);
289-
290-
$quotedMappingObjectName = preg_quote($this->getMappingObjectDefaultName(), '/');
291-
292-
foreach ($glob as $file) {
293-
$content = file_get_contents($file);
294-
295-
if (
296-
preg_match('/^#\[.*'.$quotedMappingObjectName.'\b/m', $content)
297-
|| preg_match('/^#\[.*Embeddable\b/m', $content)
298-
) {
299-
break;
300-
}
301-
if (
302-
preg_match('/^(?: \*|\/\*\*) @.*'.$quotedMappingObjectName.'\b/m', $content)
303-
|| preg_match('/^(?: \*|\/\*\*) @.*Embeddable\b/m', $content)
304-
) {
305-
$type = 'annotation';
306-
break;
307-
}
308-
}
309-
310-
return $type;
311-
}
312-
313264
/**
314265
* Loads a configured object manager metadata, query or result cache driver.
315266
*

Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,6 @@ public function testFixManagersAutoMappings(array $originalEm1, array $originalE
174174
], $expectedEm2));
175175
}
176176

177-
public function testMappingTypeDetection()
178-
{
179-
$container = $this->createContainer();
180-
181-
$reflection = new \ReflectionClass($this->extension);
182-
$method = $reflection->getMethod('detectMappingType');
183-
184-
// The ordinary fixtures contain annotation
185-
$mappingType = $method->invoke($this->extension, __DIR__.'/../Fixtures', $container);
186-
$this->assertSame($mappingType, 'attribute');
187-
188-
// In the attribute folder, attributes are used
189-
$mappingType = $method->invoke($this->extension, __DIR__.'/../Fixtures/Attribute', $container);
190-
$this->assertSame($mappingType, 'attribute');
191-
}
192-
193177
public static function providerBasicDrivers()
194178
{
195179
return [

0 commit comments

Comments
 (0)