[12.x]Add optional empty-array skipping to Arr::dot helpers #57760
+75
−9
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.
This pull request introduces an optional parameter to the Arr::dot and related helper methods, allowing developers to skip empty arrays when generating flattened keys.
By default, Arr::dot includes all keys, even those that point to empty arrays. In many cases—especially when working with configuration exports, validation rules, or API payload flattening—developers may prefer to omit empty arrays entirely to reduce noise or avoid redundant keys.
Implementation details:
Added a $skipEmptyArrays boolean parameter to the Arr::dot method and associated helper functions.
When set to true, the method skips keys whose values are empty arrays ([]).
Default behavior remains unchanged to ensure full backward compatibility.
Added unit tests to cover both scenarios (with and without skipping).
Example:
Why this is useful:
This small enhancement provides more control over data flattening, reducing the need for additional filtering steps and improving readability in use cases where empty arrays carry no meaningful data.