You are here

abstract class DiagnosticCheckBase in Purge 8.3

Describes a diagnostic check that tests a specific purging requirement.

Hierarchy

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

... See full list

File

src/Plugin/Purge/DiagnosticCheck/DiagnosticCheckBase.php, line 12

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck
View 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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DiagnosticCheckBase::$description private property The description of the check as described in the plugin's metadata.
DiagnosticCheckBase::$recommendation protected property A recommendation matching the severity level, may contain NULL.
DiagnosticCheckBase::$severity private property The severity of the outcome of this check.
DiagnosticCheckBase::$title private property The title of the check as described in the plugin's metadata.
DiagnosticCheckBase::$value protected property Optional check outcome / value (e.g. version numbers), may contain NULL.
DiagnosticCheckBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 7
DiagnosticCheckBase::getDescription public function Gets the description of the check. Overrides DiagnosticCheckInterface::getDescription
DiagnosticCheckBase::getRecommendation public function Get a recommendation matching the severity level, may return NULL. Overrides DiagnosticCheckInterface::getRecommendation
DiagnosticCheckBase::getRequirementsArray public function Generates a individual Drupal-like requirements array. Overrides DiagnosticCheckInterface::getRequirementsArray
DiagnosticCheckBase::getRequirementsSeverity public function Get the severity level, expressed as a status_report severity. Overrides DiagnosticCheckInterface::getRequirementsSeverity
DiagnosticCheckBase::getSeverity public function Get the severity level. Overrides DiagnosticCheckInterface::getSeverity
DiagnosticCheckBase::getSeverityString public function Get the severity level as unprefixed string. Overrides DiagnosticCheckInterface::getSeverityString
DiagnosticCheckBase::getTitle public function Gets the title of the check. Overrides DiagnosticCheckInterface::getTitle
DiagnosticCheckBase::getValue public function Get an optional value for the check output, may return NULL. Overrides DiagnosticCheckInterface::getValue
DiagnosticCheckBase::runCheck protected function Late runtime helper to assure that ::run() got called (and only once).
DiagnosticCheckInterface::run public function Perform the check and determine the severity level. 14
DiagnosticCheckInterface::SEVERITY_ERROR constant BLOCKING severity -- Error condition; purge.purgers service cannot operate.
DiagnosticCheckInterface::SEVERITY_INFO constant Non-blocking severity -- Informational message only.
DiagnosticCheckInterface::SEVERITY_OK constant Non-blocking severity -- check successfully passed.
DiagnosticCheckInterface::SEVERITY_WARNING constant Non-blocking severity -- Warning condition; proceed but flag warning.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.