You are here

function SensorResult::__construct in Monitoring 8

Same name and namespace in other branches
  1. 7 lib/Drupal/monitoring/Result/SensorResult.php \Drupal\monitoring\Result\SensorResult::__construct()

Instantiates a sensor result object.

By default, the sensor status is STATUS_UNKNOWN with empty message.

Parameters

\Drupal\monitoring\Entity\SensorConfig $sensor_config: Sensor config object.

array $cached_data: Result data obtained from a cache.

File

src/Result/SensorResult.php, line 80

Class

SensorResult
Generic container for the sensor result.

Namespace

Drupal\monitoring\Result

Code

function __construct(SensorConfig $sensor_config, array $cached_data = array()) {
  $this->sensorConfig = $sensor_config;
  if ($cached_data) {
    $this->data = $cached_data;
    $this->isCached = TRUE;
  }

  // Merge in defaults in case there is nothing cached for given sensor yet.
  $this->data += array(
    'sensor_status' => SensorResultInterface::STATUS_UNKNOWN,
    'sensor_message' => NULL,
    'sensor_expected_value' => NULL,
    'sensor_value' => NULL,
    'execution_time' => 0,
    'timestamp' => \Drupal::time()
      ->getRequestTime(),
  );
}