Skip to content

Make hydrators persistent with owned EntityFactory#28

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:immutable
Apr 1, 2026
Merged

Make hydrators persistent with owned EntityFactory#28
alganet merged 1 commit intoRespect:masterfrom
alganet:immutable

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Apr 1, 2026

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

@alganet alganet requested a review from Copilot April 1, 2026 12:48
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.97%. Comparing base (f95b89c) to head (0194fc2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Hydrator expose an entityFactory and split hydrate() (root entity) from hydrateAll() (full graph).
  • Update AbstractMapper to accept a Hydrator and 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
@alganet alganet marked this pull request as ready for review April 1, 2026 12:59
@alganet alganet merged commit 9663392 into Respect:master Apr 1, 2026
3 checks passed
@alganet alganet deleted the immutable branch April 1, 2026 13:00
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.

3 participants