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

Decouple UnitOfWork from Hydrators #2641

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jun 5, 2024

Q A
Type improvement
BC Break no
Fixed issues

Summary

Hydrators currently get the UnitOfWork injected directly. This leads to a circular dependency, as the DocumentManager needs a HydratorFactory, but the HydratorFactory needs a UnitOfWork instance which can't exist without a DocumentManager. To resolve this, HydratorFactory no longer takes a UnitOfWork instance, and generated hydrators instead take the UnitOfWork instance exposed by the document manager.

This PR also moves a method from UnitOfWork to the DocumentManager as it's not tied to UnitOfWork.

Note that this PR is only the first of a few refactorings necessary to properly decouple things from UnitOfWork, with the goal of having UnitOfWork represent a single set of persistable document changes. Removing the circular dependency also allows us to make hydrator factories configurable, which is important to leverage the new codec infrastructure in the PHP driver and thus speed up a lot of hydration operations.

@alcaeus alcaeus requested review from franmomu and malarzm June 5, 2024 12:29
@alcaeus alcaeus self-assigned this Jun 5, 2024
@alcaeus alcaeus changed the title Decouple hydrator uow Decouple UnitOfWork from Hydrators Jun 5, 2024
*
* @psalm-return class-string
*/
public function getClassNameForAssociation(array $mapping, $data): string
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of expanding DM's public surface but I'm not sure where else this could go... definitely not into generated hydrators as maintaining that will be PITA, ClassMetadataFactory is a no-go because of interface.

So just a food for thought, no other concerns from my end 👌

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I moved it over because it doesn't need to be in there - ideally we'd have some kind of metadata construct that allows us to get this information. Either way, I'm saving that for a future refactoring of metadata (which I don't want to tackle)

@SenseException
Copy link
Member

SenseException commented Jun 9, 2024

Are the failing shared cluster tests somehow relevant to this PR?

@alcaeus
Copy link
Member Author

alcaeus commented Jun 10, 2024

Are the failing shared cluster tests somehow relevant to this PR?

Nope, they have been failing for a while now and I haven't had a chance to dig into it and figure out what's causing them.

@alcaeus alcaeus added the Task label Jun 10, 2024
@alcaeus alcaeus merged commit f3af4bf into doctrine:2.8.x Jun 10, 2024
16 of 17 checks passed
@alcaeus alcaeus deleted the decouple-hydrator-uow branch June 10, 2024 06:38
@alcaeus alcaeus added this to the 2.8.0 milestone Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants