class BigPipeSessionless in Sessionless BigPipe 8
Same name and namespace in other branches
- 2.x src/Render/BigPipeSessionless.php \Drupal\big_pipe_sessionless\Render\BigPipeSessionless
The sessionless BigPipe service.
Hierarchy
- class \Drupal\big_pipe\Render\BigPipe
- class \Drupal\big_pipe_sessionless\Render\BigPipeSessionless
Expanded class hierarchy of BigPipeSessionless
1 file declares its use of BigPipeSessionless
- HtmlResponseBigPipeSessionlessSubscriber.php in src/
EventSubscriber/ HtmlResponseBigPipeSessionlessSubscriber.php
1 string reference to 'BigPipeSessionless'
1 service uses BigPipeSessionless
File
- src/
Render/ BigPipeSessionless.php, line 13
Namespace
Drupal\big_pipe_sessionless\RenderView source
class BigPipeSessionless extends BigPipe {
/**
* The final HTML response.
*
* Contains replaced placeholders. Its cacheability metadata and attachments
* are only for the placeholders.
*
* @var \Drupal\Core\Render\HtmlResponse
*
* @see \Drupal\big_pipe\Render\BigPipeResponse::getOriginalHtmlResponse()
* @see ::sendContent()
*/
protected $finalHtmlResponse;
/**
* The PageCache middleware.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $pageCacheMiddleware;
/**
* Sets the PageCache middleware.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $page_cache_middleware
* The page cache middleware.
*/
public function setPageCacheMiddleware(HttpKernelInterface $page_cache_middleware) {
$this->pageCacheMiddleware = $page_cache_middleware;
}
/**
* {@inheritdoc}
*/
protected function performPreSendTasks() {
// Nothing to do.
}
/**
* {@inheritdoc}
*/
protected function performPostSendTasks() {
// Nothing to do.
}
/**
* {@inheritdoc}
*/
public function sendContent(BigPipeResponse $response) {
$this->finalHtmlResponse = new HtmlResponse();
parent::sendContent($response);
$this
->primePageCache($response);
// Don't keep around any state.
$this->finalHtmlResponse = NULL;
}
/**
* {@inheritdoc}
*/
protected function sendChunk($chunk) {
// First: send.
parent::sendChunk($chunk);
// Then: track every sent chunk.
// @see ::sendContent()
if ($chunk instanceof HtmlResponse) {
$this->finalHtmlResponse
->setContent($this->finalHtmlResponse
->getContent() . $chunk
->getContent());
$this->finalHtmlResponse
->addCacheableDependency($chunk
->getCacheableMetadata());
$this->finalHtmlResponse
->addAttachments($chunk
->getAttachments());
}
else {
$this->finalHtmlResponse
->setContent($this->finalHtmlResponse
->getContent() . $chunk);
}
}
/**
* Primes the Page Cache based on the streamed response.
*
* @param \Drupal\big_pipe\Render\BigPipeResponse $response
* The BigPipe response that was sent.
*/
protected function primePageCache(BigPipeResponse $response) {
// Start with the original HTML response, so we have the appropriate meta-
// data like headers, HTTP version, and so on.
$streamed_response = $response
->getOriginalHtmlResponse();
// Override content with final HTML content (with replaced placeholders).
$streamed_response
->setContent($this->finalHtmlResponse
->getContent());
// Add any additional cacheability metadata for rendered placeholders.
$streamed_response
->addCacheableDependency($this->finalHtmlResponse
->getCacheableMetadata());
// Overwrite with final attachments (overwrite, not add, because attachments
// need to be processed, and once the response is sent, they are processed;
// if we would not overwrite, then we'd reprocess them).
// @see \Drupal\Core\Render\AttachmentsResponseProcessorInterface
$streamed_response
->setAttachments($this->finalHtmlResponse
->getAttachments());
// Dispatch the KernelEvents::RESPONSE event, to let those event subscribers
// do what they need to do. This is f.e. necessary for the cache tags header
// for debugging purposes and for modules that integrate with reverse
// proxies that support cache tags.
$fake_request = $this->requestStack
->getMasterRequest()
->duplicate();
$streamed_response = $this
->filterResponse($fake_request, HttpKernelInterface::MASTER_REQUEST, $streamed_response);
// Prime Page Cache.
// @see \Drupal\big_pipe_sessionless\StackMiddleware\BigPipeSessionlessPageCache
$this->pageCacheMiddleware
->_storeResponse($this->requestStack
->getCurrentRequest(), $streamed_response);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BigPipe:: |
protected | property | The config factory. | |
BigPipe:: |
protected | property | The event dispatcher. | |
BigPipe:: |
protected | property | The HTTP kernel. | |
BigPipe:: |
protected | property | The renderer. | |
BigPipe:: |
protected | property | The request stack. | |
BigPipe:: |
protected | property | The session. | |
BigPipe:: |
protected | function | Filters the given embedded response, using the cumulative AJAX page state. | |
BigPipe:: |
protected | function | Filters the given response. | |
BigPipe:: |
protected | function | Gets the BigPipe placeholder order. | |
BigPipe:: |
protected | function | Renders a placeholder, and just that placeholder. | |
BigPipe:: |
protected | function | Sends no-JS BigPipe placeholders' replacements as embedded HTML responses. | |
BigPipe:: |
protected | function | Sends BigPipe placeholders' replacements as embedded AJAX responses. | |
BigPipe:: |
protected | function | Sends </body> and everything after it. | |
BigPipe:: |
protected | function | Sends everything until just before </body>. | |
BigPipe:: |
private static | function | Splits a HTML string into fragments. | |
BigPipe:: |
constant | The BigPipe placeholder replacements start signal. | ||
BigPipe:: |
constant | The BigPipe placeholder replacements stop signal. | ||
BigPipe:: |
public | function | Constructs a new BigPipe class. | |
BigPipeSessionless:: |
protected | property | The final HTML response. | |
BigPipeSessionless:: |
protected | property | The PageCache middleware. | |
BigPipeSessionless:: |
protected | function |
Performs tasks after sending content (and rendering placeholders). Overrides BigPipe:: |
|
BigPipeSessionless:: |
protected | function |
Performs tasks before sending content (and rendering placeholders). Overrides BigPipe:: |
|
BigPipeSessionless:: |
protected | function | Primes the Page Cache based on the streamed response. | |
BigPipeSessionless:: |
protected | function |
Sends a chunk. Overrides BigPipe:: |
|
BigPipeSessionless:: |
public | function |
Sends an HTML response in chunks using the BigPipe technique. Overrides BigPipe:: |
|
BigPipeSessionless:: |
public | function | Sets the PageCache middleware. |