[PR #238] Add Configuration::setDefaultMetadataDriverImpl() method for convenience. #7907

Closed
opened 2026-01-22 15:57:29 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/238

State: closed
Merged: No


Current logic to setup Doctrine2 is a bit cluttered, because there's a circular dependency between $config and $driverImpl, which makes it impossible to configure things in Dependency Injection container.

$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
  doctrine.config:
    class: \Doctrine\ORM\Configuration
    calls:
      - [setMetadataCacheImpl, ['@doctrine.metadata_cache']]
      - [setMetadataDriverImpl, ['@doctrine.metadata_driver']]
      ...

Configuration is not fully initialized (and not added to service map) when setMetadataDriverImpl is called, but then setMetadataDriverImpl needs to call Configuration's newDefaultAnnotationDriver. Dependency deadlock.

I think that simpliest way to solve is to introduce setDefaultMetadataDriverImpl() method like this:

$config->setDefaultMetadataDriverImpl('/path/to/lib/MyProject/Entities');
  doctrine.config:
    class: \Doctrine\ORM\Configuration
    calls:
      - [setMetadataCacheImpl, ['@doctrine.metadata_cache']]
      - [setDefaultMetadataDriverImpl, ['/path/to/lib/MyProject/Entities']]
      ...

If you use non-default driver, you need to define everything explicitly anyway.

For default one, now you need to read annotations class and copy logic from newDefaultAnnotationDriver to DI container map on your own.

**Original Pull Request:** https://github.com/doctrine/orm/pull/238 **State:** closed **Merged:** No --- Current logic to setup Doctrine2 is a bit cluttered, because there's a circular dependency between $config and $driverImpl, which makes it impossible to configure things in Dependency Injection container. ``` php $driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities'); $config->setMetadataDriverImpl($driverImpl); ``` ``` doctrine.config: class: \Doctrine\ORM\Configuration calls: - [setMetadataCacheImpl, ['@doctrine.metadata_cache']] - [setMetadataDriverImpl, ['@doctrine.metadata_driver']] ... ``` Configuration is not fully initialized (and not added to service map) when setMetadataDriverImpl is called, but then setMetadataDriverImpl needs to call Configuration's newDefaultAnnotationDriver. Dependency deadlock. I think that simpliest way to solve is to introduce setDefaultMetadataDriverImpl() method like this: ``` php $config->setDefaultMetadataDriverImpl('/path/to/lib/MyProject/Entities'); ``` ``` doctrine.config: class: \Doctrine\ORM\Configuration calls: - [setMetadataCacheImpl, ['@doctrine.metadata_cache']] - [setDefaultMetadataDriverImpl, ['/path/to/lib/MyProject/Entities']] ... ``` If you use non-default driver, you need to define everything explicitly anyway. For default one, now you need to read annotations class and copy logic from newDefaultAnnotationDriver to DI container map on your own.
admin added the pull-request label 2026-01-22 15:57:29 +01:00
admin closed this issue 2026-01-22 15:57:29 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7907