protected static function JobSchedulerCronTab::parseElement in Job Scheduler 7.2
Parse each text element. Recursive up to some point...
1 call to JobSchedulerCronTab::parseElement()
- JobSchedulerCronTab::values in ./
JobSchedulerCronTab.inc - Parse array of values, check whether this is valid.
File
- ./
JobSchedulerCronTab.inc, line 199 - JobSchedulerCronTab class.
Class
- JobSchedulerCronTab
- Jose's cron tab parser = Better try only simple crontab strings.
Code
protected static function parseElement($type, $string, $translate = FALSE) {
$string = trim($string);
if ($translate) {
$string = self::translateNames($type, $string);
}
if ($string === '*') {
// This means all possible values, return right away, no need to double
// check.
return self::possibleValues($type);
}
elseif (strpos($string, '/')) {
// Multiple. Example */2, for weekday will expand into 2, 4, 6.
list($values, $multiple) = explode('/', $string);
$values = self::parseElement($type, $values);
foreach ($values as $value) {
if (!($value % $multiple)) {
$range[] = $value;
}
}
}
elseif (strpos($string, ',')) {
// Now process list parts, expand into items, process each and merge back.
$list = explode(',', $string);
$range = array();
foreach ($list as $item) {
if ($values = self::parseElement($type, $item)) {
$range = array_merge($range, $values);
}
}
}
elseif (strpos($string, '-')) {
// This defines a range. Example 1-3, will expand into 1,2,3.
list($start, $end) = explode('-', $string);
// Double check the range is within possible values.
$range = range($start, $end);
}
elseif (is_numeric($string)) {
// This looks like a single number, double check it's int.
$range = array(
(int) $string,
);
}
// Return unique sorted values and double check they're within possible
// values.
if (!empty($range)) {
$range = array_intersect(array_unique($range), self::possibleValues($type));
sort($range);
// Sunday validation. We need cron values to match PHP values, thus week
// day 7 is not allowed, must be 0.
if ($type == 'wday' && in_array(7, $range)) {
array_pop($range);
array_unshift($range, 0);
}
return $range;
}
else {
// No match found for this one, will produce an error with validation.
return array();
}
}