HttpBundledPurger.php in Generic HTTP Purger 8
File
src/Plugin/Purge/Purger/HttpBundledPurger.php
View source
<?php
namespace Drupal\purge_purger_http\Plugin\Purge\Purger;
use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgerInterface;
class HttpBundledPurger extends HttpPurgerBase 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,
]);
}
}
}