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.
A preface
Arrayable
introduces thetoArray()
method for objects to convert into JSON-ish objects.ArrayableFields
adds filtering and optional 'extra' fields.This PR introduces deep filtering of child items to
ArrayableFields
as well as filtering to the genericArrays::toArray()
helper.An example
A tree like:
Now
toArray()
will give you all the fields of the root and of every child - with respect to thefields()
config of each object.Filtering exists already, but was limited to the root object. So although one can restrict whole fields/children the entire array conversion of each 'child' field is included if specified. In the example above, one couldn't get only
deep2
without also gettingdeep3
.So we've introduced this syntax:
Which produces this:
Extra fields
Extra fields are things not included in the standard output of the
fields()
config, perhaps they're too big, or they're expensive to compute. One can 'add' these to their output using the 2nd parameter:But again, we're restricted to full objects and only the extra fields of the root item. The filtering updates from fields also resolve this.
At times we will also want to indiscriminately get an extra field from all items in the tree.
Draft because
My tests are still broken for wildcards :(