BigPipe::sendContent

public BigPipe::sendContent($content, array $attachments)

Sends an HTML response in chunks using the BigPipe technique.

Parameters

string $content: The HTML response content to send.

array $attachments: The HTML response's attachments.

Overrides BigPipeInterface::sendContent

File

core/modules/big_pipe/src/Render/BigPipe.php, line 112

Class

BigPipe
The default BigPipe service.

Namespace

Drupal\big_pipe\Render

Code

public function sendContent($content, array $attachments) {
  // First, gather the BigPipe placeholders that must be replaced.
  $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : [];
  $nojs_placeholders = isset($attachments['big_pipe_nojs_placeholders']) ? $attachments['big_pipe_nojs_placeholders'] : [];

  // BigPipe sends responses using "Transfer-Encoding: chunked". To avoid
  // sending already-sent assets, it is necessary to track cumulative assets
  // from all previously rendered/sent chunks.
  // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41
  $cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]);
  $cumulative_assets->setAlreadyLoadedLibraries($attachments['library']);

  // The content in the placeholders may depend on the session, and by the
  // time the response is sent (see index.php), the session is already closed.
  // Reopen it for the duration that we are rendering placeholders.
  $this->session->start();

  // Find the closing </body> tag and get the strings before and after. But be
  // careful to use the latest occurrence of the string "</body>", to ensure
  // that strings in inline JavaScript or CDATA sections aren't used instead.
  $parts = explode('</body>', $content);
  $post_body = array_pop($parts);
  $pre_body = implode('', $parts);

  $this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets);
  $this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body, $placeholders), $cumulative_assets);
  $this->sendPostBody($post_body);

  // Close the session again.
  $this->session->save();

  return $this;
}
doc_Drupal
2016-10-29 08:46:14
Comments
Leave a Comment

Please login to continue.