ConfigurationCheck.php in Generic HTTP Purger 8
File
src/Plugin/Purge/DiagnosticCheck/ConfigurationCheck.php
View source
<?php
namespace Drupal\purge_purger_http\Plugin\Purge\DiagnosticCheck;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface;
use Drupal\purge_purger_http\Entity\HttpPurgerSettings;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ConfigurationCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $purgePurgers;
public final function __construct(array $configuration, $plugin_id, $plugin_definition, PurgersServiceInterface $purge_purgers) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$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('purge.purgers'));
}
public function run() {
$plugins = [];
foreach ($this->purgePurgers
->getPluginsEnabled() as $id => $plugin_id) {
if (in_array($plugin_id, [
'http',
'httpbundled',
])) {
$plugins[$id] = HttpPurgerSettings::load($id);
}
}
$labels = $this->purgePurgers
->getLabels();
foreach ($plugins as $id => $settings) {
$t = [
'@purger' => $labels[$id],
];
foreach ([
'name',
'hostname',
'port',
'request_method',
'scheme',
] as $f) {
if (empty($settings->{$f})) {
$this->recommendation = $this
->t("@purger not configured.", $t);
return self::SEVERITY_ERROR;
}
}
if ($settings->scheme === 'https' && $settings->port != 443) {
$this->recommendation = $this
->t("@purger uses https:// but its port is not 443!", $t);
return self::SEVERITY_WARNING;
}
if ($settings->scheme === 'http' && $settings->port == 443) {
$this->recommendation = $this
->t("@purger uses http:// but its port is 443!", $t);
return self::SEVERITY_WARNING;
}
}
$this->recommendation = $this
->t("All purgers configured.");
return self::SEVERITY_OK;
}
}