You are here

public static function JobSchedulerCronTab::values in Job Scheduler 8.3

Same name and namespace in other branches
  1. 8.2 src/JobSchedulerCronTab.php \Drupal\job_scheduler\JobSchedulerCronTab::values()

Parses an array of values, check whether this is valid.

Parameters

array $array: A crontab array to validate.

Return value

null|array The validated elements or null if the input was invalid.

Overrides JobSchedulerCronTabInterface::values

2 calls to JobSchedulerCronTab::values()
JobSchedulerCronTab::parse in src/JobSchedulerCronTab.php
Parses a full crontab string into an array of type => values.
JobSchedulerCronTab::__construct in src/JobSchedulerCronTab.php
Constructs a JobSchedulerCronTab object.

File

src/JobSchedulerCronTab.php, line 58

Class

JobSchedulerCronTab
Class for job scheduler crontab.

Namespace

Drupal\job_scheduler

Code

public static function values(array $array) {
  if (count($array) == 5) {
    $values = array_combine([
      'minutes',
      'hours',
      'mday',
      'mon',
      'wday',
    ], array_map('trim', $array));
    $elements = [];
    foreach ($values as $type => $string) {
      $elements[$type] = self::parseElement($type, $string, TRUE);
    }

    // Returns only if we have the right number of elements.
    // Dangerous means works running every second or things like that.
    if (count(array_filter($elements)) == 5) {
      return $elements;
    }
  }
  return NULL;
}