— this contains BigPipe
* placeholders for the personalized parts of the page. Hence this sends the
* non-personalized parts of the page. Let's call it The Skeleton.
* 2. N chunks: a ';
/**
* The BigPipe placeholder replacements stop signal.
*
* @var string
*/
const STOP_SIGNAL = '';
public function __construct(
protected RendererInterface $renderer,
protected SessionInterface $session,
protected RequestStack $requestStack,
protected HttpKernelInterface $httpKernel,
protected EventDispatcherInterface $eventDispatcher,
protected ConfigFactoryInterface $configFactory,
protected MessengerInterface $messenger,
protected RequestContext $requestContext,
protected LoggerInterface $logger,
protected bool $debugCacheabilityHeaders = FALSE,
) {
}
/**
* Performs tasks after sending content (and rendering placeholders).
*/
protected function performPostSendTasks() {
// Close the session again.
$this->session->save();
}
/**
* Sends a chunk.
*
* @param string|\Drupal\Core\Render\HtmlResponse $chunk
* The string or response to append. String if there's no cacheability
* metadata or attachments to merge.
*/
protected function sendChunk($chunk) {
assert(is_string($chunk) || $chunk instanceof HtmlResponse);
if ($chunk instanceof HtmlResponse) {
print $chunk->getContent();
}
else {
print $chunk;
}
flush();
}
/**
* Sends an HTML response in chunks using the BigPipe technique.
*
* @param \Drupal\big_pipe\Render\BigPipeResponse $response
* The BigPipe response to send.
*
* @internal
* This method should only be invoked by
* \Drupal\big_pipe\Render\BigPipeResponse, which is itself an internal
* class.
*/
public function sendContent(BigPipeResponse $response) {
$content = $response->getContent();
$attachments = $response->getAttachments();
// First, gather the BigPipe placeholders that must be replaced.
$placeholders = $attachments['big_pipe_placeholders'] ?? [];
$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 https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41
$cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]);
$cumulative_assets->setAlreadyLoadedLibraries($attachments['library']);
// Find the closing