Skip to content

Commit

Permalink
Expose a setting to opt-in for the XSD validation for mapping (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jun 5, 2023
1 parent 6c273c9 commit b2ec6c2
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/doctrine-1.0.xsd
Expand Up @@ -228,6 +228,7 @@
<xsd:attribute name="entity-listener-resolver" type="xsd:string" />
<xsd:attribute name="repository-factory" type="xsd:string" />
<xsd:attribute name="report-fields-where-declared" type="xsd:boolean" />
<xsd:attribute name="validate-xml-mapping" type="xsd:boolean" />
</xsd:attributeGroup>

<xsd:complexType name="filter" mixed="true">
Expand Down
2 changes: 2 additions & 0 deletions Resources/doc/configuration.rst
Expand Up @@ -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: ~
Expand Down
5 changes: 5 additions & 0 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]);
}

Expand Down Expand Up @@ -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,
]);
}

Expand Down
Expand Up @@ -16,7 +16,7 @@
<mapping name="AnnotationsBundle" />
<mapping name="AttributesBundle" type="attribute" />
</entity-manager>
<entity-manager name="em2">
<entity-manager name="em2" validate-xml-mapping="true">
<mapping name="YamlBundle" dir="Resources/config/doctrine" alias="yml" />
<mapping name="manual" type="xml" prefix="Fixtures\Bundles\XmlBundle"
dir="%kernel.root_dir%/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine"
Expand Down
Expand Up @@ -11,7 +11,7 @@
<connection name="default" dbname="db" />
</dbal>

<orm>
<orm validate-xml-mapping="true">
<mapping name="AnnotationsBundle" />
<mapping name="AttributesBundle" type="attribute" />
<mapping name="YamlBundle" dir="Resources/config/doctrine" alias="yml" />
Expand Down
Expand Up @@ -14,6 +14,7 @@ doctrine:
AttributesBundle:
type: attribute
em2:
validate_xml_mapping: true
mappings:
YamlBundle:
dir: Resources/config/doctrine
Expand Down
Expand Up @@ -6,6 +6,7 @@ doctrine:
dbname: db

orm:
validate_xml_mapping: true
mappings:
AnnotationsBundle: ~
AttributesBundle:
Expand Down
1 change: 1 addition & 0 deletions Tests/TestCase.php
Expand Up @@ -60,6 +60,7 @@ public function createXmlBundleTestContainer(): ContainerBuilder
'default_entity_manager' => 'default',
'entity_managers' => [
'default' => [
'validate_xml_mapping' => true,
'mappings' => [
'XmlBundle' => [
'type' => 'xml',
Expand Down
1 change: 0 additions & 1 deletion Tests/baseline-ignore

This file was deleted.

10 changes: 9 additions & 1 deletion UPGRADE-2.10.md
Expand Up @@ -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.
- `Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface` has been deprecated. Use the `#[AsDoctrineListener]` attribute instead.
4 changes: 0 additions & 4 deletions phpunit.xml.dist
Expand Up @@ -7,10 +7,6 @@
</testsuite>
</testsuites>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./Tests/baseline-ignore"/>
</php>

<filter>
<whitelist>
<directory>.</directory>
Expand Down

0 comments on commit b2ec6c2

Please sign in to comment.