From b2ec6c2668f6dc514e8bf51257d19c7c19398afe Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 5 Jun 2023 16:43:41 +0200 Subject: [PATCH] Expose a setting to opt-in for the XSD validation for mapping (#1670) --- DependencyInjection/Configuration.php | 1 + DependencyInjection/DoctrineExtension.php | 4 ++++ Resources/config/schema/doctrine-1.0.xsd | 1 + Resources/doc/configuration.rst | 2 ++ .../AbstractDoctrineExtensionTest.php | 5 +++++ .../config/xml/orm_multiple_em_bundle_mappings.xml | 2 +- .../config/xml/orm_single_em_bundle_mappings.xml | 2 +- .../config/yml/orm_multiple_em_bundle_mappings.yml | 1 + .../config/yml/orm_single_em_bundle_mappings.yml | 1 + Tests/TestCase.php | 1 + Tests/baseline-ignore | 1 - UPGRADE-2.10.md | 10 +++++++++- phpunit.xml.dist | 4 ---- 13 files changed, 27 insertions(+), 8 deletions(-) delete mode 100644 Tests/baseline-ignore diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 41f970bc0..641a4408e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -659,6 +659,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition ->prototype('scalar')->end() ->end() ->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() + ->booleanNode('validate_xml_mapping')->defaultFalse()->info('Set to "true" to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.14 and will be mandatory in ORM 3.0. See https://github.com/doctrine/orm/pull/6728.')->end() ->end() ->children() ->arrayNode('second_level_cache') diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index ca54a9265..524d520b6 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -23,6 +23,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Id\AbstractIdGenerator; +use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver; use Doctrine\ORM\Proxy\Autoloader; use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand; use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand; @@ -836,6 +837,9 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager, $args[2] = $entityManager['report_fields_where_declared']; } elseif ($driverType === 'attribute') { $args[1] = $entityManager['report_fields_where_declared']; + } elseif ($driverType === 'xml') { + $args[1] ??= SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION; + $args[2] = $entityManager['validate_xml_mapping']; } else { continue; } diff --git a/Resources/config/schema/doctrine-1.0.xsd b/Resources/config/schema/doctrine-1.0.xsd index c23c875c1..74ee16b6c 100644 --- a/Resources/config/schema/doctrine-1.0.xsd +++ b/Resources/config/schema/doctrine-1.0.xsd @@ -228,6 +228,7 @@ + diff --git a/Resources/doc/configuration.rst b/Resources/doc/configuration.rst index a86515aa0..397c34ca3 100644 --- a/Resources/doc/configuration.rst +++ b/Resources/doc/configuration.rst @@ -248,6 +248,8 @@ Configuration Reference auto_mapping: false # Opt-in to new mapping driver mode as of Doctrine ORM 2.16, https://github.com/doctrine/orm/pull/10455 report_fields_where_declared: false + # 0pt-in to the new mapping driver mode as of Doctrine ORM 2.14. See https://github.com/doctrine/orm/pull/6728. + validate_xml_mapping: false naming_strategy: doctrine.orm.naming_strategy.default quote_strategy: doctrine.orm.quote_strategy.default entity_listener_resolver: ~ diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index eeaabc6bb..d56d95f7c 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Schema\LegacySchemaManagerFactory; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver; use Generator; use InvalidArgumentException; use PDO; @@ -523,6 +524,8 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void $xmlDef = $container->getDefinition('doctrine.orm.default_xml_metadata_driver'); $this->assertDICConstructorArguments($xmlDef, [ [__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'XmlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\XmlBundle'], + SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION, + true, ]); } @@ -579,6 +582,8 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void $xmlDef = $container->getDefinition('doctrine.orm.em2_xml_metadata_driver'); $this->assertDICConstructorArguments($xmlDef, [ [__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'XmlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\XmlBundle'], + SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION, + true, ]); } diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml index 667994333..9f7b64f84 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml @@ -16,7 +16,7 @@ - + - + diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml index cd2205dfa..3fe52bd5a 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml @@ -14,6 +14,7 @@ doctrine: AttributesBundle: type: attribute em2: + validate_xml_mapping: true mappings: YamlBundle: dir: Resources/config/doctrine diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml index ad573c677..c30a56f26 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml @@ -6,6 +6,7 @@ doctrine: dbname: db orm: + validate_xml_mapping: true mappings: AnnotationsBundle: ~ AttributesBundle: diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 9c56a81e2..770340796 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -60,6 +60,7 @@ public function createXmlBundleTestContainer(): ContainerBuilder 'default_entity_manager' => 'default', 'entity_managers' => [ 'default' => [ + 'validate_xml_mapping' => true, 'mappings' => [ 'XmlBundle' => [ 'type' => 'xml', diff --git a/Tests/baseline-ignore b/Tests/baseline-ignore deleted file mode 100644 index 7ec032ab8..000000000 --- a/Tests/baseline-ignore +++ /dev/null @@ -1 +0,0 @@ -%Using XML mapping driver with XSD validation disabled is deprecated% \ No newline at end of file diff --git a/UPGRADE-2.10.md b/UPGRADE-2.10.md index 831f16701..e9e03c27c 100644 --- a/UPGRADE-2.10.md +++ b/UPGRADE-2.10.md @@ -14,6 +14,14 @@ In version 2.10+ of this bundle, a new configuration setting `report_fields_wher Unless you set it to `true`, Doctrine ORM will emit deprecation messages mentioning this new setting. +### Preparing for the XSD validation for XML drivers + +Doctrine ORM 2.14+ adds support for validating the XSD of XML mapping files. In ORM 3.0, this validation will be mandatory. + +As the ecosystem is known to rely on custom elements in the XML mapping files that are forbidden when validating the XSD (for instance when using `gedmo/doctrine-extensions`), this validation is opt-in thanks to a `validate_xml_mapping` setting at the entity manager configuration level. + +Unless you set it to `true`, Doctrine ORM will emit deprecation messages mentioning the XSD validation. + ### Deprecations -- `Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface` has been deprecated. Use the `#[AsDoctrineListener]` attribute instead. \ No newline at end of file +- `Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface` has been deprecated. Use the `#[AsDoctrineListener]` attribute instead. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59a8f7c96..e48328406 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,10 +7,6 @@ - - - - .