VarnishBundledPurger.php in Varnish purger 8.2
File
src/Plugin/Purge/Purger/VarnishBundledPurger.php
View source
<?php
namespace Drupal\varnish_purger\Plugin\Purge\Purger;
use Drupal\purge\Plugin\Purge\Purger\PurgerInterface;
use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface;
class VarnishBundledPurger extends VarnishPurgerBase implements PurgerInterface {
public function invalidate(array $invalidations) {
$set_state = function ($state) use ($invalidations) {
foreach ($invalidations as $invalidation) {
$invalidation
->setState($state);
}
};
$token_data = [
'invalidations' => $invalidations,
];
$uri = $this
->getUri($token_data);
$opt = $this
->getOptions($token_data);
try {
$this->client
->request($this->settings->request_method, $uri, $opt);
$set_state(InvalidationInterface::SUCCEEDED);
} catch (\Exception $e) {
$set_state(InvalidationInterface::FAILED);
$headers = $opt['headers'];
unset($opt['headers']);
$debug = json_encode(str_replace("\n", ' ', [
'msg' => $e
->getMessage(),
'uri' => $uri,
'method' => $this->settings->request_method,
'guzzle_opt' => $opt,
'headers' => $headers,
]));
$this
->logger()
->emergency("item failed due @e, details (JSON): @debug", [
'@e' => get_class($e),
'@debug' => $debug,
]);
}
}
}