function StreamedJsonResponse::streamArray
1 call to StreamedJsonResponse::streamArray()
- StreamedJsonResponse::streamData in vendor/
symfony/ http-foundation/ StreamedJsonResponse.php
File
-
vendor/
symfony/ http-foundation/ StreamedJsonResponse.php, line 93
Class
- StreamedJsonResponse
- StreamedJsonResponse represents a streamed HTTP response for JSON.
Namespace
Symfony\Component\HttpFoundationCode
private function streamArray(array $data, int $jsonEncodingOptions, int $keyEncodingOptions) : void {
$generators = [];
array_walk_recursive($data, function (&$item, $key) use (&$generators) {
if (self::PLACEHOLDER === $key) {
// if the placeholder is already in the structure it should be replaced with a new one that explode
// works like expected for the structure
$generators[] = $key;
}
// generators should be used but for better DX all kind of Traversable and objects are supported
if (\is_object($item)) {
$generators[] = $item;
$item = self::PLACEHOLDER;
}
elseif (self::PLACEHOLDER === $item) {
// if the placeholder is already in the structure it should be replaced with a new one that explode
// works like expected for the structure
$generators[] = $item;
}
});
$jsonParts = explode('"' . self::PLACEHOLDER . '"', json_encode($data, $jsonEncodingOptions));
foreach ($generators as $index => $generator) {
// send first and between parts of the structure
echo $jsonParts[$index];
$this->streamData($generator, $jsonEncodingOptions, $keyEncodingOptions);
}
// send last part of the structure
echo $jsonParts[array_key_last($jsonParts)];
}