ConfigurationCheck.php in Varnish purger 8.2
File
src/Plugin/Purge/DiagnosticCheck/ConfigurationCheck.php
View source
<?php
namespace Drupal\varnish_purger\Plugin\Purge\DiagnosticCheck;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\varnish_purger\Entity\VarnishPurgerSettings;
class ConfigurationCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $purgePurgers;
public 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, [
'varnish',
'varnishbundled',
])) {
$plugins[$id] = VarnishPurgerSettings::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;
}
}