You are here

protected function DomPdf::setupHttpContext in Entity Print 8.2

Setup the HTTP Context used by Dompdf for requesting resources.

1 call to DomPdf::setupHttpContext()
DomPdf::__construct in src/Plugin/EntityPrint/PrintEngine/DomPdf.php
Constructs a \Drupal\Component\Plugin\PluginBase object.

File

src/Plugin/EntityPrint/PrintEngine/DomPdf.php, line 243

Class

DomPdf
A Entity Print plugin for the DomPdf library.

Namespace

Drupal\entity_print\Plugin\EntityPrint\PrintEngine

Code

protected function setupHttpContext() {
  $context_options = [
    'ssl' => [
      'verify_peer' => $this->configuration['verify_peer'],
      'verify_peer_name' => $this->configuration['verify_peer_name'],
    ],
  ];
  if ($this->configuration['cafile']) {
    $context_options['ssl']['cafile'] = $this->configuration['cafile'];
  }

  // If we have authentication then add it to the request context.
  if (!empty($this->configuration['username'])) {
    $auth = base64_encode(sprintf('%s:%s', $this->configuration['username'], $this->configuration['password']));
    $context_options['http']['header'] = [
      'Authorization: Basic ' . $auth,
    ];
  }
  $http_context = stream_context_create($context_options);
  $this->dompdf
    ->setHttpContext($http_context);
}