abstract class DiagnosticCheckBase in Purge 8.3
Describes a diagnostic check that tests a specific purging requirement.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase implements DiagnosticCheckInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DiagnosticCheckBase
6 files declare their use of DiagnosticCheckBase
- AlwaysErrorDiagnosticCheck.php in tests/
modules/ purge_check_error_test/ src/ Plugin/ Purge/ DiagnosticCheck/ AlwaysErrorDiagnosticCheck.php - AlwaysInfoDiagnosticCheck.php in tests/
modules/ purge_check_test/ src/ Plugin/ Purge/ DiagnosticCheck/ AlwaysInfoDiagnosticCheck.php - AlwaysOkDiagnosticCheck.php in tests/
modules/ purge_check_test/ src/ Plugin/ Purge/ DiagnosticCheck/ AlwaysOkDiagnosticCheck.php - AlwaysWarningDiagnosticCheck.php in tests/
modules/ purge_check_warning_test/ src/ Plugin/ Purge/ DiagnosticCheck/ AlwaysWarningDiagnosticCheck.php - PurgerSpecificWarningDiagnosticCheck.php in tests/
modules/ purge_check_test/ src/ Plugin/ Purge/ DiagnosticCheck/ PurgerSpecificWarningDiagnosticCheck.php
File
- src/
Plugin/ Purge/ DiagnosticCheck/ DiagnosticCheckBase.php, line 12
Namespace
Drupal\purge\Plugin\Purge\DiagnosticCheckView source
abstract class DiagnosticCheckBase extends PluginBase implements DiagnosticCheckInterface {
/**
* The title of the check as described in the plugin's metadata.
*
* @var \Drupal\Core\StringTranslation\TranslatableMarkup
*/
private $title;
/**
* The description of the check as described in the plugin's metadata.
*
* @var \Drupal\Core\StringTranslation\TranslatableMarkup
*/
private $description;
/**
* The severity of the outcome of this check.
*
* This value corresponds to one of these constants:
* - DiagnosticCheckInterface::SEVERITY_INFO
* - DiagnosticCheckInterface::SEVERITY_OK
* - DiagnosticCheckInterface::SEVERITY_WARNING
* - DiagnosticCheckInterface::SEVERITY_ERROR.
*
* @var int
*/
private $severity;
/**
* A recommendation matching the severity level, may contain NULL.
*
* @var null|string|\Drupal\Core\StringTranslation\TranslatableMarkup
*/
protected $recommendation;
/**
* Optional check outcome / value (e.g. version numbers), may contain NULL.
*
* @var mixed
*/
protected $value;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* Late runtime helper to assure that ::run() got called (and only once).
*/
protected function runCheck() {
if (!is_null($this->severity)) {
return;
}
$this->severity = $this
->run();
if (!is_int($this->severity)) {
$class = $this
->getPluginDefinition()['class'];
throw new CheckNotImplementedCorrectly("Exected integer as return from {$class}::run()!");
}
if ($this->severity < -1 || $this->severity > 2) {
$class = $this
->getPluginDefinition()['class'];
throw new CheckNotImplementedCorrectly("Invalid const returned by {$class}::run()!");
}
}
/**
* {@inheritdoc}
*/
public function getTitle() {
$this
->runCheck();
if (is_null($this->title)) {
$this->title = $this
->getPluginDefinition()['title'];
}
return $this->title;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$this
->runCheck();
if (is_null($this->description)) {
$this->description = $this
->getPluginDefinition()['description'];
}
return $this->description;
}
/**
* {@inheritdoc}
*/
public function getSeverity() {
$this
->runCheck();
return $this->severity;
}
/**
* {@inheritdoc}
*/
public function getSeverityString() {
$this
->runCheck();
$mapping = [
self::SEVERITY_INFO => 'INFO',
self::SEVERITY_OK => 'OK',
self::SEVERITY_WARNING => 'WARNING',
self::SEVERITY_ERROR => 'ERROR',
];
return $mapping[$this
->getSeverity()];
}
/**
* {@inheritdoc}
*/
public function getRecommendation() {
$this
->runCheck();
if ($this->recommendation) {
return $this->recommendation;
}
else {
return $this
->getDescription();
}
}
/**
* {@inheritdoc}
*/
public function getValue() {
$this
->runCheck();
return $this->value;
}
/**
* {@inheritdoc}
*/
public function getRequirementsArray() {
$this
->runCheck();
return [
'title' => (string) $this
->getTitle(),
'value' => (string) $this
->getValue(),
'description' => (string) $this
->getRecommendation(),
'severity_status' => strtolower($this
->getSeverityString()),
'severity' => $this
->getRequirementsSeverity(),
];
}
/**
* {@inheritdoc}
*/
public function getRequirementsSeverity() {
static $mapping;
$this
->runCheck();
if (is_null($mapping)) {
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Currently, our constants hold the exact same values as core's
// requirement constants. However, as our diagnostic checks API is more
// than just a objectification of hook_requirements we need to assure
// that this lasts over time, and thus map the constants.
$mapping = [
self::SEVERITY_INFO => REQUIREMENT_INFO,
self::SEVERITY_OK => REQUIREMENT_OK,
self::SEVERITY_WARNING => REQUIREMENT_WARNING,
self::SEVERITY_ERROR => REQUIREMENT_ERROR,
];
}
return $mapping[$this
->getSeverity()];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DiagnosticCheckBase:: |
private | property | The description of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | A recommendation matching the severity level, may contain NULL. | |
DiagnosticCheckBase:: |
private | property | The severity of the outcome of this check. | |
DiagnosticCheckBase:: |
private | property | The title of the check as described in the plugin's metadata. | |
DiagnosticCheckBase:: |
protected | property | Optional check outcome / value (e.g. version numbers), may contain NULL. | |
DiagnosticCheckBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
7 |
DiagnosticCheckBase:: |
public | function |
Gets the description of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get a recommendation matching the severity level, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Generates a individual Drupal-like requirements array. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level, expressed as a status_report severity. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get the severity level as unprefixed string. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Gets the title of the check. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
public | function |
Get an optional value for the check output, may return NULL. Overrides DiagnosticCheckInterface:: |
|
DiagnosticCheckBase:: |
protected | function | Late runtime helper to assure that ::run() got called (and only once). | |
DiagnosticCheckInterface:: |
public | function | Perform the check and determine the severity level. | 14 |
DiagnosticCheckInterface:: |
constant | BLOCKING severity -- Error condition; purge.purgers service cannot operate. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Informational message only. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- check successfully passed. | ||
DiagnosticCheckInterface:: |
constant | Non-blocking severity -- Warning condition; proceed but flag warning. | ||
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |