DDC-1559: GH-238: Add Configuration::setDefaultMetadataDriverImpl() method for convenience. #1954

Closed
opened 2026-01-22 13:33:24 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Dec 23, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @beberlei:

Pull-Request was automatically synchronized: https://github.com/doctrine/doctrine2/pull/238

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.

Originally created by @doctrinebot on GitHub (Dec 23, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @beberlei: Pull-Request was automatically synchronized: https://github.com/doctrine/doctrine2/pull/238 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 Bug label 2026-01-22 13:33:24 +01:00
admin closed this issue 2026-01-22 13:33:27 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Dec 28, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1954