Make hydrators persistent with owned EntityFactory#28
Merged
alganet merged 1 commit intoRespect:masterfrom Apr 1, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #28 +/- ##
=========================================
Coverage 97.96% 97.97%
- Complexity 290 291 +1
=========================================
Files 17 17
Lines 590 592 +2
=========================================
+ Hits 578 580 +2
Misses 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors hydration so hydrators are long-lived objects that own their EntityFactory, and mappers derive entityFactory/style from the hydrator (inverting the prior dependency direction).
Changes:
- Make
Hydratorexpose anentityFactoryand splithydrate()(root entity) fromhydrateAll()(full graph). - Update
AbstractMapperto accept aHydratorand remove per-collection hydrator overrides (Collection::$hydrator,hydrateFrom(),defaultHydrator(),resolveHydrator()). - Update hydrator implementations and tests to use the new API and construction pattern (
new Nested(new EntityFactory(...))).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Hydrator.php | Updates hydrator contract: persistent entityFactory, adds hydrateAll() and narrows hydrate() to root entity. |
| src/Hydrators/Base.php | Introduces owned EntityFactory and default hydrate() implementation delegating to hydrateAll(). |
| src/Hydrators/Nested.php | Adapts nested hydrator to use owned EntityFactory and implement hydrateAll(). |
| src/Hydrators/PrestyledAssoc.php | Adapts pre-styled assoc hydrator to use owned EntityFactory and implement hydrateAll(). |
| src/AbstractMapper.php | Mapper now takes a Hydrator; exposes derived entityFactory/style; removes default/collection hydrator resolution. |
| src/Collections/Collection.php | Removes per-collection hydrator state and hydrateFrom() override. |
| tests/InMemoryMapper.php | Switches to hydrateAll() via mapper-owned hydrator; removes default hydrator override. |
| tests/Hydrators/NestedTest.php | Updates tests for hydrateAll() and adds coverage for new hydrate() root-entity behavior. |
| tests/Hydrators/PrestyledAssocTest.php | Updates tests to construct hydrator with an EntityFactory and call hydrateAll(). |
| tests/AbstractMapperTest.php | Updates to construct mappers with a hydrator and validates style derivation via hydrator’s factory. |
| tests/Collections/CollectionTest.php | Removes hydrateFrom() test and updates mapper construction to pass a hydrator. |
| tests/Styles/Sakila/SakilaIntegrationTest.php | Updates integration test to pass Hydrator (Nested) into InMemoryMapper. |
| tests/Styles/Plural/PluralIntegrationTest.php | Updates integration test to pass Hydrator (Nested) into InMemoryMapper. |
| tests/Styles/NorthWind/NorthWindIntegrationTest.php | Updates integration test to pass Hydrator (Nested) into InMemoryMapper. |
| tests/Styles/CakePHP/CakePHPIntegrationTest.php | Updates integration test to pass Hydrator (Nested) into InMemoryMapper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Hydrators are now long-lived objects that own their EntityFactory instead of receiving it as a parameter on every call. The mapper derives its entityFactory and style from the hydrator, inverting the previous dependency direction. - Add entityFactory property to Hydrator interface - Split hydrate() (returns root entity) from hydrateAll() (returns full graph) - Remove $hydrator property and hydrateFrom() from Collection - Remove defaultHydrator()/resolveHydrator() from AbstractMapper - Mapper constructor now takes Hydrator instead of EntityFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hydrators are now long-lived objects that own their EntityFactory instead of receiving it as a parameter on every call. The mapper derives its entityFactory and style from the hydrator, inverting the previous dependency direction.