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

Add ClassMetadataFactoryInterface to allow switching implementation #11497

Open
wants to merge 1 commit into
base: 3.2.x
Choose a base branch
from

Conversation

alekitto
Copy link

New Feature

Q A
New Feature yes
RFC no
BC Break no

Summary

Fixes #11496

This PR introduces a new ClassMetadataFactoryInterface interface and changes the type-hints to allow switching implementation of the factory in configuration.

@@ -154,6 +154,7 @@

<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming">
<exclude-pattern>src/EntityManagerInterface.php</exclude-pattern>
<exclude-pattern>src/Mapping/ClassMetadataFactoryInterface.php</exclude-pattern>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this excluded from phpcs checks? It's going to be a new interface that you can name without the superflous naming.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine\ORM\Mapping\ClassMetadataFactory is already used (is the name of the current implementation).
Do you have a better proposal for the name of this interface?

Comment on lines +381 to +384
$reflectionClass = new ReflectionClass($cmfName);
if (! $reflectionClass->implementsInterface(ClassMetadataFactoryInterface::class)) {
throw InvalidClassMetadataFactory::create($cmfName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would introduce an exception when there was not one before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to this PR a call with a class different from Doctrine\ORM\Mapping\ClassMetadataFactory would cause a TypeError. So yes, it would not throw an exception here, but in a different (and completely unrelated) point of the code, which can be harder to debug.

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

Successfully merging this pull request may close these issues.

Cannot override the class metadata factory via configuration since 3.0
2 participants