/** * @param string $cronHours * @return bool */ protected function isHoursPresentable($cronHours) { /** * not presentable if cronHours do not match any of the following values: * * (every hour), * *slash{one or more digits} (e.g., *slash8 - every 8 hours) * string containing comma (e.g. 0,8,16 - specified hours), * {one or more digits}-{one or more digits} (e.g. 16-19 - from 16 to 19 h), * {one or more digits} (e.g. 0 - midnight) */ if ($cronHours !== '*' && !preg_match('#\\*/(\\d+)#', $cronHours) && strpos($cronHours, ',') === false && !preg_match('#(\\d+)-(\\d+)#', $cronHours) && !preg_match('#\\d+#', $cronHours)) { return false; } //if hours contain '/' and '-' signs, e.g. 3-11/2, it is not presentable if (strpos($cronHours, '/') !== false && strpos($cronHours, '-') !== false) { return false; } $everyxHoursArray = Noovias_Cron_Data_CronExpression_Settings_Hour::getEachHourArray(); /** * if cron hours are of the form *slash{one or more digits} check whether the value of * every x hours is in the Array, which is also used by template rendering cron expression drop-downs */ if (strpos($cronHours, '*/') !== false) { if (!in_array(intval(substr($cronHours, 2)), $everyxHoursArray)) { return false; } } /** * in case of from-to specification: * * '-' should separate exactly 2 elements * entries should be numeric and between 0 and 23 */ if (strpos($cronHours, '-') !== false) { $hours = explode('-', $cronHours); if (count($hours) !== 2) { return false; } foreach ($hours as $hour) { if (!is_numeric($hour)) { return false; } if (intval($hour) > 23 || intval($hour) < 0) { return false; } } } if (strpos($cronHours, ',') !== false) { $hours = explode(',', $cronHours); foreach ($hours as $hour) { if (!is_numeric($hour)) { return false; } if (intval($hour) > 23 || intval($hour) < 0) { return false; } } } if (preg_match('#\\d+#', $cronHours)) { if (intval($cronHours) > 23 || intval($cronHours) < 0) { return false; } } return true; }
public function getEachHourArray() { return Noovias_Cron_Data_CronExpression_Settings_Hour::getEachHourArray(); }