Skip to content

Commit 3a021a7

Browse files
committed
bug symfony#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: doctrine/DoctrineBundle#1322 Commits ------- cecaa78 [DoctrineBridge] Allow bundles to define a driver type "attribute"
2 parents d5e8d6e + cecaa78 commit 3a021a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
151151
}
152152

153153
if (!$bundleConfig['dir']) {
154-
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp'])) {
154+
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
155155
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
156156
} else {
157157
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
@@ -193,6 +193,10 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
193193
$args[0] = array_merge(array_values($driverPaths), $args[0]);
194194
}
195195
$mappingDriverDef->setArguments($args);
196+
} elseif ('attribute' === $driverType) {
197+
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
198+
array_values($driverPaths),
199+
]);
196200
} elseif ('annotation' == $driverType) {
197201
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
198202
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
@@ -236,8 +240,8 @@ protected function assertValidMappingConfiguration(array $mappingConfig, $object
236240
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
237241
}
238242

239-
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) {
240-
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')));
243+
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp', 'attribute'])) {
244+
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')));
241245
}
242246
}
243247

@@ -437,7 +441,7 @@ protected function getMetadataDriverClass(string $driverType): string
437441
{
438442
@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);
439443

440-
return '%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%');
444+
return '%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class').'%';
441445
}
442446

443447
/**

0 commit comments

Comments
 (0)