Skip to content

[DoctrineBridge] Configure the attribute driver with class names or file Finder #61535

@GromNaN

Description

@GromNaN

Description

In doctrine/persistence#433, we added a new way to configure the doctrine attribute driver by setting a ClassLocator instance instead of a list of directories. The ClassLocator instance can be a ClassNames (list of class names) or a FileClassLocator (with a Finder instance to list files).

This is implemented by doctrine/orm#12131 and doctrine/mongodb-odm#2802.

We now need to configure this in Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension:

foreach ($this->drivers as $driverType => $driverPaths) {
$mappingService = $this->getObjectManagerElementName($objectManager['name'].'_'.$driverType.'_metadata_driver');
if ($container->hasDefinition($mappingService)) {
$mappingDriverDef = $container->getDefinition($mappingService);
$args = $mappingDriverDef->getArguments();
$args[0] = array_merge(array_values($driverPaths), $args[0]);
$mappingDriverDef->setArguments($args);
} else {
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
array_values($driverPaths),
]);
}

I want to use the resource discovery feature of the the DIC to inject the classes with the #[Entity] (and similar) attribute. But a different driver is configured for each entity manager. We need a way to assign the Entity Manager of each entity class, in the bundle configuration of using an attribute on the entity class. With a fallback to the default EM to simplify configuration when there is only 1 EM.

Example

Suggestion using a new attribute:

namespace App\SomeEntity;

use Doctrine\Bundle\DoctrineBundle\Attribute\EntityManager;

#[EntityManager('some_em')]
#[ORM\Entity]
class Article { }

Suggestion using a configuration:

doctrine:
    dbal: ...
    orm:
        entity_managers:
            some_em:
                mappings:
                    SomeEntity:
                        type: attribute
                        namespace: App\SomeEntity\

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions