Skip to content

Commit 34e96aa

Browse files
committed
Add a new report_fields_where_declared config setting
This adds a new config setting `report_fields_where_declared` that makes it easy to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.16 and will be mandatory in ORM 3.0. For details, see doctrine/orm#10455. I think that since this bundle allows to specify the mapping configuration per entity manager, it would make sense to have this new config setting at the entity manager level as well.
1 parent e6da248 commit 34e96aa

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

DependencyInjection/Configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
628628
->arrayNode('schema_ignore_classes')
629629
->prototype('scalar')->end()
630630
->end()
631+
->scalarNode('report_fields_where_declared')->defaultFalse()->info('Set to "true" to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.16 and will be mandatory in ORM 3.0. See https://github.com/doctrine/orm/pull/10455.')->end()
631632
->end()
632633
->children()
633634
->arrayNode('second_level_cache')

DependencyInjection/DoctrineExtension.php

+16
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,22 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager,
820820
$this->loadMappingInformation($entityManager, $container);
821821
$this->registerMappingDrivers($entityManager, $container);
822822

823+
$chainDriverDef = $container->getDefinition($this->getObjectManagerElementName($entityManager['name'] . '_metadata_driver'));
824+
foreach (array_keys($this->drivers) as $driverType) {
825+
$mappingService = $this->getObjectManagerElementName($entityManager['name'] . '_' . $driverType . '_metadata_driver');
826+
$mappingDriverDef = $container->getDefinition($mappingService);
827+
$args = $mappingDriverDef->getArguments();
828+
if ($driverType === 'annotation') {
829+
$args[2] = $entityManager['report_fields_where_declared'];
830+
} elseif ($driverType === 'attribute') {
831+
$args[1] = $entityManager['report_fields_where_declared'];
832+
} else {
833+
continue;
834+
}
835+
836+
$mappingDriverDef->setArguments($args);
837+
}
838+
823839
$ormConfigDef->addMethodCall('setEntityNamespaces', [$this->aliasMap]);
824840
}
825841

Resources/doc/configuration.rst

+4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ Configuration Reference
246246
class_metadata_factory_name: Doctrine\ORM\Mapping\ClassMetadataFactory
247247
default_repository_class: Doctrine\ORM\EntityRepository
248248
auto_mapping: false
249+
# Opt-in to new mapping driver mode as of Doctrine ORM 2.16, https://github.com/doctrine/orm/pull/10455
250+
report_fields_where_declared: false
249251
naming_strategy: doctrine.orm.naming_strategy.default
250252
quote_strategy: doctrine.orm.quote_strategy.default
251253
entity_listener_resolver: ~
@@ -496,6 +498,7 @@ Configuration Reference
496498
class-metadata-factory-name="Doctrine\ORM\Mapping\ClassMetadataFactory"
497499
default-repository-class="Doctrine\ORM\EntityRepository"
498500
auto-mapping="false"
501+
report-fields-where-declared="false"
499502
naming-strategy="doctrine.orm.naming_strategy.default"
500503
quote-strategy="doctrine.orm.quote_strategy.default"
501504
entity-listener-resolver="null"
@@ -652,6 +655,7 @@ the ORM resolves to:
652655
metadata_cache_driver: ~
653656
query_cache_driver: ~
654657
result_cache_driver: ~
658+
report_fields_where_declared: false
655659
656660
There are lots of other configuration options that you can use to overwrite
657661
certain classes, but those are for very advanced use-cases only.

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void
499499
[
500500
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity',
501501
],
502+
false,
502503
]);
503504

504505
$ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver');
@@ -554,6 +555,7 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void
554555
[
555556
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity',
556557
],
558+
false,
557559
]);
558560

559561
$ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver');

UPGRADE-2.10.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
UPGRADE FROM 2.9 to 2.10
2+
========================
3+
4+
Configuration
5+
-------------
6+
7+
### Preparing for a new `report_fields_where_declared` mapping driver mode
8+
9+
Doctrine ORM 2.16+ makes a change to how the annotations and attribute mapping drivers report fields inherited from parent classes. For details, see https://github.com/doctrine/orm/pull/10455. It will trigger a deprecation notice unless the new mode is activated. In ORM 3.0, the new mode will be the only one.
10+
11+
The new mode ~does not~ should not make a difference for regular, valid use cases, but may lead to `MappingException`s for users with certain configurations that were not meant to be supported by the ORM in the first place. To avoid surprising users (even when their configuration is invalid) during a 2.16 _minor_ version upgrade, the transition to this new mode was implemented as an opt-in. This way, you can try and deal with the change any time you see fit.
12+
13+
In version 2.10+ of this bundle, a new configuration setting `report_fields_where_declared` was added at the entity manager configuration level. Set it to `true` to switch the mapping driver for the corresponding entity manager to the new mode. It is only relevant for mapping configurations using attributes or annotations.
14+
15+
Unless you set it to `true`, Doctrine ORM will emit deprecation messages mentioning this new setting.

0 commit comments

Comments
 (0)