PurgersAvailableDiagnosticCheck.php in Purge 8.3
File
src/Plugin/Purge/DiagnosticCheck/PurgersAvailableDiagnosticCheck.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\DiagnosticCheck;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PurgersAvailableDiagnosticCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $configFactory;
protected $purgePurgers;
public final function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, PurgersServiceInterface $purge_purgers) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->purgePurgers = $purge_purgers;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('purge.purgers'));
}
public function run() {
$purgerlabels = $this->purgePurgers
->getLabels();
$this->value = '';
if (!empty($purgerlabels)) {
$this->value = [];
foreach ($purgerlabels as $label) {
$this->value[] = (string) $label;
}
$this->value = implode(', ', $this->value);
}
if (empty($purgerlabels)) {
$this->recommendation = $this
->t("There is no purger loaded which means that you need a module enabled to provide a purger plugin to clear your external cache or CDN.");
return self::SEVERITY_ERROR;
}
elseif (count($purgerlabels) == 1) {
$this->recommendation = $this
->t("Purger configured.");
return self::SEVERITY_OK;
}
elseif (count($purgerlabels) > 3) {
$this->recommendation = $this
->t("You have more than 3 purgers active on one system. This introduces the risk of congesting Drupal as multiple purgers are clearing external caches. It is highly recommended is to simplify your caching architecture if possible.");
return self::SEVERITY_WARNING;
}
else {
$this->recommendation = $this
->t("Purgers configured.");
return self::SEVERITY_OK;
}
}
}