[HttpFoundation] Support root-level Generator in StreamedJsonResponse #51538
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.
Currently the
StreamedJsonResponse
only supports streaming nested Generators within an array data structure.However if a response is a list of items (for example database entities) on the root level, this isn't usable.
I think both usecases can be supported with the change in this PR.
The root level generator doesn't account for additional nested generators yet. I could add that by doing
is_array($item)
and the call the recursive placeholder logic.Link to first PR that introduced StreamedJsonResponse: #47709
Also something I noticed is I only got intermediate output, when adding aEdit: I see the class' PhpDoc describes this and it's probably expected to be done in userland implementations.flush()
call after each item has been echo'd (with asleep(1)
after each item to see it output the parts individually).