Skip to content

Add ClassMetadataFactoryInterface to allow switching implementation#11497

Closed
alekitto wants to merge 1 commit intodoctrine:3.2.xfrom
alekitto:3.2.x
Closed

Add ClassMetadataFactoryInterface to allow switching implementation#11497
alekitto wants to merge 1 commit intodoctrine:3.2.xfrom
alekitto:3.2.x

Conversation

@alekitto
Copy link
Copy Markdown

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.

Comment thread phpcs.xml.dist

<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming">
<exclude-pattern>src/EntityManagerInterface.php</exclude-pattern>
<exclude-pattern>src/Mapping/ClassMetadataFactoryInterface.php</exclude-pattern>
Copy link
Copy Markdown
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
Copy Markdown
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 thread src/Configuration.php
Comment on lines +381 to +384
$reflectionClass = new ReflectionClass($cmfName);
if (! $reflectionClass->implementsInterface(ClassMetadataFactoryInterface::class)) {
throw InvalidClassMetadataFactory::create($cmfName);
}
Copy link
Copy Markdown
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
Copy Markdown
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.

@alekitto
Copy link
Copy Markdown
Author

alekitto commented Nov 5, 2024

@SenseException any news on this?

@beberlei
Copy link
Copy Markdown
Member

beberlei commented Nov 5, 2024

@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.

@alekitto
Copy link
Copy Markdown
Author

alekitto commented Nov 5, 2024

@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 ClassMetadata object in order to support associations on embeddables.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 5, 2025

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions Bot added the Stale label Feb 5, 2025
@alekitto
Copy link
Copy Markdown
Author

alekitto commented Feb 5, 2025

Not stale. Waiting for a response

@github-actions github-actions Bot removed the Stale label Feb 6, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2025

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions Bot added the Stale label May 7, 2025
@alekitto
Copy link
Copy Markdown
Author

alekitto commented May 7, 2025

Not stale. Still waiting for a response.

@github-actions github-actions Bot removed the Stale label May 8, 2025
@greg0ire greg0ire deleted the branch doctrine:3.2.x July 4, 2025 06:10
@greg0ire greg0ire closed this Jul 4, 2025
@alekitto
Copy link
Copy Markdown
Author

alekitto commented Jul 4, 2025

Sorry @greg0ire why this PR has been closed?

@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Jul 4, 2025

Sorry, it was closed because I deleted the branch. Feel free to reopen against another branch.

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

4 participants