Skip to content
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

Cannot override the class metadata factory via configuration since 2.5.0 #2551

Closed
alekitto opened this issue Sep 25, 2023 · 3 comments · Fixed by #2552
Closed

Cannot override the class metadata factory via configuration since 2.5.0 #2551

alekitto opened this issue Sep 25, 2023 · 3 comments · Fixed by #2552
Milestone

Comments

@alekitto
Copy link

BC Break Report

Q A
BC Break yes
Version 2.5.0

Summary

Since version 2.5.0, the class metadata factory cannot be overridden.

Previous behavior

The document manager has been instantiated taking the class name from the configuration on document manager construction

Current behavior

Since 5987555 the override is broken as the document manager is wired to the final class Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory.
To allow overriding via configuration, it should be wired against Doctrine\Persistence\Mapping\ClassMetadataFactory interface.

How to reproduce

$config = new Configuration();
$config->setClassMetadataFactoryName(FakeMetadataFactory::class);
DocumentManager::create(config: $config);
@malarzm
Copy link
Member

malarzm commented Sep 27, 2023

This one's more tricky because of the initialization step

$this->metadataFactory = new $metadataFactoryClassName();
$this->metadataFactory->setDocumentManager($this);
$this->metadataFactory->setConfiguration($this->config);

for which Persistence's interface is not sufficient. Most probably we should introduce our own interface.

Offhand, what's your use case for custom metadata factory?

@malarzm malarzm added this to the 2.5.3 milestone Sep 27, 2023
@malarzm malarzm added the Bug label Sep 27, 2023
@alekitto
Copy link
Author

Most probably we should introduce our own interface.

Agree

Offhand, what's your use case for custom metadata factory?

It is mostly used for testing actually: I'm using a DocumentManager with a mocked connection and a custom metadata factory in order to precisely control what is returned from the factory itself

malarzm added a commit that referenced this issue Oct 23, 2023
Introduce ClassMetadataFactoryInterface to allow switching implementations
@malarzm
Copy link
Member

malarzm commented Oct 23, 2023

Closing as #2552 got merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants