-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: 3.2.x
Are you sure you want to change the base?
Conversation
@@ -154,6 +154,7 @@ | |||
|
|||
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"> | |||
<exclude-pattern>src/EntityManagerInterface.php</exclude-pattern> | |||
<exclude-pattern>src/Mapping/ClassMetadataFactoryInterface.php</exclude-pattern> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
$reflectionClass = new ReflectionClass($cmfName); | ||
if (! $reflectionClass->implementsInterface(ClassMetadataFactoryInterface::class)) { | ||
throw InvalidClassMetadataFactory::create($cmfName); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@SenseException any news on this? |
@alekitto can you explain what your use case is in overwriting the CMF this way? Just trying to asses what is the overall idea. Historically we didn't like overwriting any of the internal classes, which I would count the CMF. |
I already did that on the issue: #11496 (comment) I'm overriding the metadata factory with a mocked/fake version of it in unit tests, to precisely control what has been returned and test libraries and classes in isolation. The configuration object still allow to overwrite the class name of the class metadata factory, and I always used that in testing and, for example, to override the |
New Feature
Summary
Fixes #11496
This PR introduces a new
ClassMetadataFactoryInterface
interface and changes the type-hints to allow switching implementation of the factory in configuration.