Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StreamedJsonResponse.php

function StreamedJsonResponse::streamIterable

1 call to StreamedJsonResponse::streamIterable()
StreamedJsonResponse::streamData in vendor/symfony/http-foundation/StreamedJsonResponse.php

File

vendor/symfony/http-foundation/StreamedJsonResponse.php, line 128

Class

StreamedJsonResponse
StreamedJsonResponse represents a streamed HTTP response for JSON.

Namespace

Symfony\Component\HttpFoundation

Code

private function streamIterable(iterable $iterable, int $jsonEncodingOptions, int $keyEncodingOptions) : void {
    $isFirstItem = true;
    $startTag = '[';
    foreach ($iterable as $key => $item) {
        if ($isFirstItem) {
            $isFirstItem = false;
            // depending on the first elements key the generator is detected as a list or map
            // we can not check for a whole list or map because that would hurt the performance
            // of the streamed response which is the main goal of this response class
            if (0 !== $key) {
                $startTag = '{';
            }
            echo $startTag;
        }
        else {
            // if not first element of the generic, a separator is required between the elements
            echo ',';
        }
        if ('{' === $startTag) {
            echo json_encode((string) $key, $keyEncodingOptions) . ':';
        }
        $this->streamData($item, $jsonEncodingOptions, $keyEncodingOptions);
    }
    if ($isFirstItem) {
        // indicates that the generator was empty
        echo '[';
    }
    echo '[' === $startTag ? ']' : '}';
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal