You are here

class HtmlResponseAttachmentsProcessor in HTTP/2 Server Push 8

Decorates the HTML response attachments processor service, adds Server Push.

Hierarchy

Expanded class hierarchy of HtmlResponseAttachmentsProcessor

See also

\Drupal\http2_server_push\Asset\CssCollectionRenderer

\Drupal\http2_server_push\Asset\JsCollectionRenderer

1 string reference to 'HtmlResponseAttachmentsProcessor'
http2_server_push.services.yml in ./http2_server_push.services.yml
http2_server_push.services.yml
1 service uses HtmlResponseAttachmentsProcessor
html_response.attachments_processor.http2_server_push in ./http2_server_push.services.yml
\Drupal\http2_server_push\Render\HtmlResponseAttachmentsProcessor

File

src/Render/HtmlResponseAttachmentsProcessor.php, line 15

Namespace

Drupal\http2_server_push\Render
View source
class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorInterface {

  /**
   * The decorated HTML response attachments processor service.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
   */
  protected $htmlResponseAttachmentsProcessor;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Constructs a HtmlResponseAttachmentsProcessor object.
   *
   * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
   *   The decorated HTML response attachments processor service.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor, RequestStack $request_stack) {
    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
    $this->requestStack = $request_stack;
  }

  /**
   * {@inheritdoc}
   */
  public function processAttachments(AttachmentsInterface $response) {
    $response = $this->htmlResponseAttachmentsProcessor
      ->processAttachments($response);
    $request = $this->requestStack
      ->getCurrentRequest();
    if ($request->attributes
      ->has('http2_server_push_link_headers')) {
      $new_link_headers = $request->attributes
        ->get('http2_server_push_link_headers');
      $existing_link_headers = $response->headers
        ->get('Link', NULL, FALSE);
      $merged_link_headers = array_unique(array_merge($existing_link_headers, $new_link_headers));
      $response->headers
        ->set('Link', $merged_link_headers, TRUE);
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HtmlResponseAttachmentsProcessor::$htmlResponseAttachmentsProcessor protected property The decorated HTML response attachments processor service.
HtmlResponseAttachmentsProcessor::$requestStack protected property The request stack.
HtmlResponseAttachmentsProcessor::processAttachments public function Processes the attachments of a response that has attachments. Overrides AttachmentsResponseProcessorInterface::processAttachments
HtmlResponseAttachmentsProcessor::__construct public function Constructs a HtmlResponseAttachmentsProcessor object.