/** * @param string $cronMinutes * @return bool */ protected function isMinutesPresentable($cronMinutes) { /** * not presentable if cronMinutes do not match any of the following values: * * (every minute), * *slash{one or more digits} (e.g., *slash15 - every 15 minutes) * string containing comma (e.g. 10,20,30 - specified minutes), * {one or more digits}-{one or more digits} (e.g. 40-50 - from 40 to 50 min), * {one or more digits} (e.g. 0 - at the beginnin of every hour) */ if ($cronMinutes !== '*' && !preg_match('#\\*/(\\d+)#', $cronMinutes) && strpos($cronMinutes, ',') === false && !preg_match('#(\\d+)-(\\d+)#', $cronMinutes) && !preg_match('#\\d+#', $cronMinutes)) { return false; } //if minutes contain '/' and '-' signs, e.g. 3-55/15, it is not presentable if (strpos($cronMinutes, '/') !== false && strpos($cronMinutes, '-') !== false) { return false; } $everyxMinutesArray = Noovias_Cron_Data_CronExpression_Settings_Minute::getEachMinuteArray(); /** * if cron minutes are of the form *slash{one or more digits} check whether the value of * every x minutes is in the Array, which is also used by template rendering cron expression drop-downs */ if (strpos($cronMinutes, '*/') !== false) { if (!in_array(intval(substr($cronMinutes, 2)), $everyxMinutesArray)) { return false; } } /** * in case of from-to specification: * * '-' should separate exactly 2 elements * entries should be numeric and between 0 and 59 */ if (strpos($cronMinutes, '-') !== false) { $minutes = explode('-', $cronMinutes); if (count($minutes) !== 2) { return false; } foreach ($minutes as $minute) { if (!is_numeric($minute)) { return false; } if (intval($minute) > 59 || intval($minute) < 0) { return false; } } } if (strpos($cronMinutes, ',') !== false) { $minutes = explode(',', $cronMinutes); foreach ($minutes as $minute) { if (!is_numeric($minute)) { return false; } if (intval($minute) > 59 || intval($minute) < 0) { return false; } } } if (preg_match('#\\d+#', $cronMinutes)) { if (intval($cronMinutes) > 59 || intval($cronMinutes) < 0) { return false; } } return true; }
/** * @return array */ public function getEachMinuteArray() { return Noovias_Cron_Data_CronExpression_Settings_Minute::getEachMinuteArray(); }