You are here

public function CdnWarmer::warmMultiple in Warmer 8

Same name and namespace in other branches
  1. 2.x modules/warmer_cdn/src/Plugin/warmer/CdnWarmer.php \Drupal\warmer_cdn\Plugin\warmer\CdnWarmer::warmMultiple()

Warms multiple items.

Parameters

array $items: The items to warm.

Return value

int The number of items that were successfully warmed.

Overrides WarmerInterface::warmMultiple

File

modules/warmer_cdn/src/Plugin/warmer/CdnWarmer.php, line 58

Class

CdnWarmer
The cache warmer for the built-in entity cache.

Namespace

Drupal\warmer_cdn\Plugin\warmer

Code

public function warmMultiple(array $items = []) {
  $headers = $this
    ->parseHeaders();
  $verify = (bool) $this
    ->getConfiguration()['verify'];
  $responses = array_map(function ($url) use ($headers, $verify) {
    try {
      return $this->httpClient
        ->request('GET', $url, [
        'headers' => $headers,
        'verify' => $verify,
      ]);
    } catch (ClientException $exception) {
      return $exception
        ->getResponse();
    } catch (RequestException $exception) {
      return $exception
        ->getResponse();
    }
  }, $items);
  $responses = array_filter($responses, function ($res) {
    return $res instanceof ResponseInterface;
  });
  $successful = array_filter($responses, function (ResponseInterface $res) {
    return $res
      ->getStatusCode() < 399;
  });
  return count($successful);
}