Skip to content

Support patchlevel/hydrator 2 - #29

Merged
DavidBadura merged 4 commits into
2.0.xfrom
hydrator-2
Nov 7, 2026
Merged

DavidBadura merged 4 commits into
2.0.xfrom
hydrator-2

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Moves the library to hydrator 2.1.1 and drops support for 1.x, since HydratorWithContext and NormalizerWithContext are gone in v2 and the plain Hydrator in v1 has no context. The repositories and managers now take a Hydrator, and custom normalizers in the docs and fixtures get the context argument. 2.1.1 is needed because 2.1.0 drops array shape keys without a normalizer.

DocumentHydrator no longer implements the Hydrator interface. In v2 that interface works on mixed data, but documents are always arrays and the class is only used inside the repositories, so it is internal now and throws DocumentNotExtractable if the hydrator does not return an array.

The new docs/UPGRADE-2.0.md covers these changes. Builds on #31, which fixes CI on 2.0.x, so please merge that first. Further fixes found along the way follow as separate PRs.

Replaces #21.

PHPStan 2.2 types variadic parameters as arrays that may have string keys, so
the objects passed on to insertMany() and bulkWrite() no longer satisfied the
list types and the baseline entries stopped matching. Normalizing the objects
with array_values() also makes the $objects[0] access safe when a repository is
called with named arguments.

The mapping methods now declare that they throw UnknownPropertyPath, which
PHPStan needs to accept a call whose result is unused in the tests.
MongoDB 8.x refuses to start on the current GitHub runners because their
kernel is 6.19 or newer (SERVER-121912). 9.0 starts fine.
Hydrator 2 merged HydratorWithContext and NormalizerWithContext into the
Hydrator and Normalizer interfaces, so the repositories now take a plain
Hydrator and the normalizers in the docs and fixtures get the context
argument. 2.1.1 is the first release that keeps array shape keys without a
normalizer, which 2.1.0 dropped.

DocumentHydrator no longer implements the Hydrator interface. In v2 that
interface works on mixed data, while documents are always arrays and the
class is only used inside the repositories. It is now internal and throws
DocumentNotExtractable if the hydrator does not return an array.
Covers the switch to hydrator 2 for custom normalizers, custom hydrators and
the DocumentHydrator.
@DavidBadura
DavidBadura marked this pull request as ready for review November 7, 2026 11:22
@DavidBadura
DavidBadura merged commit e40c3dc into 2.0.x Nov 7, 2026
17 of 20 checks passed
@DavidBadura
DavidBadura deleted the hydrator-2 branch November 7, 2026 11:28
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.

1 participant