feat(transformer): add ArrayShapeTransformer and support for array shape#336
Open
nlemoine wants to merge 3 commits intojolicode:mainfrom
Open
feat(transformer): add ArrayShapeTransformer and support for array shape#336nlemoine wants to merge 3 commits intojolicode:mainfrom
nlemoine wants to merge 3 commits intojolicode:mainfrom
Conversation
joelwurtz
reviewed
Mar 19, 2026
| } | ||
|
|
||
| return new ArrayShapeTransformer($fieldTransformers); | ||
| } |
Member
There was a problem hiding this comment.
I think you should add a new factory instead, this one is mainly for collection, just set the correct priority in factory to be sure that it's executed before (also in the bundle)
joelwurtz
reviewed
Mar 19, 2026
| $newSource = $source->withType($fieldSourceType); | ||
| $newTarget = $target->withType($fieldTargetType); | ||
|
|
||
| $fieldTransformer = $this->chainTransformerFactory->getTransformer($newSource, $newTarget, $mapperMetadata); |
Member
There was a problem hiding this comment.
I'm not sure about that, you only change the type but in fact it's a whole other field / sub property, since we mainly guess on type it should be ok, but there may be case of this giving the wrong code IMO, let's keep it for now (no need to change) don't want to over complexify this
Member
|
I'm 👍 on this, can you move the factory in its own file and i think we will merge this after. |
…taFactory and update transformers configuration
Contributor
Author
|
Thanks for your feedback @joelwurtz. I moved the array shape handling into its own factory. |
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.
Hi @joelwurtz,
#330 added casting for array but that only works for homogeneous collections (one cast in a loop). Shapes like
array{name: string, age: int, score: float}need a different approach sinceArrayShapeType::getCollectionValueType()returns a union of all value types and loses the per-key info.I added an ArrayShapeTransformer that generates per-key code instead of a uniform loop. Optional keys (nickname?) get an
array_key_existsguard. Works with nested shapes, objects, DateTime, nullable fields, and collections inside shapes. Also handles object-to-object mapping when source and target shapes have different types.Let me know if changes are needed.