Repository navigation
Pass the hydrator to normalizers via the context - #215
Merged
Merged
Conversation
The StackHydrator injected itself into every HydratorAwareNormalizer of the loaded metadata. That mutated shared, cached metadata and made it hard for a hydrator which wraps the StackHydrator to see nested objects. The hydrator is now passed with every call in the context under Hydrator::HYDRATOR. Each hydrator only sets it if it is missing, so the outermost one wins. HydratorAwareNormalizer and the setHydrator() methods of the built-in normalizers are removed.
|
Hello 👋 here is the most recent benchmark result:
This comment gets update everytime a new commit comes in! |
DanielBadura
approved these changes
Oct 6, 2026
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.
Normalizers which hydrate or extract nested objects no longer get the hydrator injected, they read it from the context under the new key
Hydrator::HYDRATOR.Until now the
StackHydratorcalledsetHydrator()on everyHydratorAwareNormalizerof a class when its metadata was loaded. That mutated the normalizers inside the (possibly cached and shared) metadata, and a hydrator wrapping theStackHydrator, like a tracing decorator, never saw the nested objects because the normalizers kept pointing to the inner hydrator. In #150 that needed an extra root hydrator mechanism to rewire the normalizers after the decorators were applied.Now every hydrator sets
$context[Hydrator::HYDRATOR] ??= $thiswhen it is called. The outermost hydrator wins automatically, so a wrapper only has to add that one line to see nested objects, and the metadata stays untouched.This is a BC break for 3.0:
HydratorAwareNormalizeris removed, custom normalizers read the hydrator from the context instead.ObjectNormalizer,ObjectMapNormalizer,ArrayNormalizerandArrayShapeNormalizerlosesetHydrator().As a small side effect
ObjectNormalizerandObjectMapNormalizeronly throwMissingHydratorwhen they really need the hydrator,nullvalues work without one.The changes are documented in a new
docs/UPGRADE-3.0.md.