Skip to content

Allow configuring class names through methods instead of class parameters in Doctrine extensions #33319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ DoctrineBridge
* Deprecated passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field.
* Deprecated not passing an `IdReader` to the `DoctrineChoiceLoader` when the query can be optimized with single id field.
* Deprecated `RegistryInterface`, use `Doctrine\Common\Persistence\ManagerRegistry`.
* Added a new `getMetadataDriverClass` method to replace class parameters in `AbstractDoctrineExtension`. This method
will be abstract in Symfony 5 and must be declared in extending classes.

Filesystem
----------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ DoctrineBridge
* Passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field will throw an exception, pass `null` instead
* Not passing an `IdReader` to the `DoctrineChoiceLoader` when the query can be optimized with single id field will not apply any optimization
* The `RegistryInterface` has been removed.
* Added a new `getMetadataDriverClass` method in `AbstractDoctrineExtension` to replace class parameters.

DomCrawler
----------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* added `DoctrineClearEntityManagerMiddleware`
* deprecated `RegistryInterface`, use `Doctrine\Common\Persistence\ManagerRegistry`
* added support for invokable event listeners
* added `getMetadataDriverClass` method to deprecate class parameters in service configuration files

4.3.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
if ($container->hasDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'))) {
$chainDriverDef = $container->getDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'));
} else {
$chainDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.driver_chain.class%'));
$chainDriverDef = new Definition($this->getMetadataDriverClass('driver_chain'));
$chainDriverDef->setPublic(false);
}

Expand All @@ -194,12 +194,12 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
}
$mappingDriverDef->setArguments($args);
} elseif ('annotation' == $driverType) {
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
array_values($driverPaths),
]);
} else {
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
array_values($driverPaths),
]);
}
Expand Down Expand Up @@ -434,6 +434,16 @@ abstract protected function getMappingResourceConfigDirectory();
*/
abstract protected function getMappingResourceExtension();

/**
* The class name used by the various mapping drivers.
*/
protected function getMetadataDriverClass(string $driverType): string
{
@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%');
}

/**
* Search for a manager that is declared as 'auto_mapping' = true.
*
Expand Down