bug #40793 [DoctrineBridge] Add support for a driver type "attribute" (beberlei)

This PR was merged into the 4.4 branch.

Discussion
----------

[DoctrineBridge] Add support for a driver type "attribute"

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| License       | MIT

Without this change its not possible to use attributes for mapping when they get released in ORM 2.9 over the next days. Otherwise we would need to copy three methods from the `AbstractDoctrineExtension` into the Bundle. See the DoctrineBundle PR that makes the full changes: https://github.com/doctrine/DoctrineBundle/pull/1322

Commits
-------

cecaa7815a [DoctrineBridge] Allow bundles to define a driver type "attribute"
This commit is contained in:
Nyholm 2021-04-16 16:09:41 +02:00
commit 3a021a7fc4
No known key found for this signature in database
GPG Key ID: D6332DE2B6F8FA38

View File

@ -151,7 +151,7 @@ abstract class AbstractDoctrineExtension extends Extension
}
if (!$bundleConfig['dir']) {
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp'])) {
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
} else {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
@ -193,6 +193,10 @@ abstract class AbstractDoctrineExtension extends Extension
$args[0] = array_merge(array_values($driverPaths), $args[0]);
}
$mappingDriverDef->setArguments($args);
} elseif ('attribute' === $driverType) {
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
array_values($driverPaths),
]);
} elseif ('annotation' == $driverType) {
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
@ -236,8 +240,8 @@ abstract class AbstractDoctrineExtension extends Extension
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
}
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) {
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or "staticphp" 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')));
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp', 'attribute'])) {
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')));
}
}
@ -437,7 +441,7 @@ abstract class AbstractDoctrineExtension extends Extension
{
@trigger_error(sprintf('Not declaring the "%s" method in class "%s" is deprecated since Symfony 4.4. This method will be abstract in Symfony 5.0.', __METHOD__, static::class), \E_USER_DEPRECATED);
return '%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%');
return '%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class').'%';
}
/**