41 $cronCommand = trim($cronCommand);
56 switch ($cronCommand) {
59 $cronCommand =
'0 0 1 1 *';
62 $cronCommand =
'0 0 1 * *';
65 $cronCommand =
'0 0 * * 0';
70 $cronCommand =
'0 0 * * *';
73 $cronCommand =
'0 * * * *';
93 $normalizedCronCommand = implode(
' ', $fieldArray);
94 return $normalizedCronCommand;
106 $fields = explode(
' ', $cronCommand);
108 throw new \InvalidArgumentException(
'Unable to split given cron command to five fields.', 1291227373);
122 if ((
string)$expression ===
'*') {
126 $listOfCommaValues = explode(
',', $expression);
128 foreach ($listOfCommaValues as $listElement) {
129 if (strpos($listElement,
'/') !==
false) {
130 list($left, $right) = explode(
'/', $listElement);
131 if (strpos($left,
'-') !==
false) {
132 list($leftBound, $rightBound) = explode(
'-', $left);
135 $left = $leftBound .
'-' . $rightBound;
137 if ((
string)$left !==
'*') {
141 $fieldArray[] = $left .
'/' . $right;
142 } elseif (strpos($listElement,
'-') !==
false) {
143 list($left, $right) = explode(
'-', $listElement);
146 $fieldArray[] = $left .
'-' . $right;
151 $fieldValues = implode(
',', $fieldArray);
167 if ((
string)$expression ===
'*') {
170 $listOfCommaValues = explode(
',', $expression);
172 foreach ($listOfCommaValues as $listElement) {
173 if (strpos($listElement,
'/') !==
false) {
174 list($left, $right) = explode(
'/', $listElement);
175 if ((
string)$left ===
'*') {
181 } elseif (strpos($listElement,
'-') !==
false) {
184 $fieldArray[] = $listElement;
185 } elseif (strlen($listElement) === 2 && $listElement[0] ===
'0') {
186 $fieldArray[] = (int)$listElement;
188 throw new \InvalidArgumentException(
'Unable to normalize integer field.', 1291429389);
191 $fieldValues = implode(
',', $fieldArray);
193 if ((
string)$fieldValues ===
'') {
194 throw new \InvalidArgumentException(
'Unable to convert integer field to list of values: Result list empty.', 1291422012);
196 if ((
string)$fieldValues !==
'*') {
197 $fieldList = explode(
',', $fieldValues);
199 $fieldList = array_unique($fieldList);
200 if (current($fieldList) < $lowerBound) {
201 throw new \InvalidArgumentException(
'Lowest element in list is smaller than allowed.', 1291470084);
203 if (end($fieldList) > $upperBound) {
204 throw new \InvalidArgumentException(
'An element in the list is higher than allowed.', 1291470170);
206 $fieldValues = implode(
',', $fieldList);
208 return (
string)$fieldValues;
220 if ((
string)$range ===
'') {
221 throw new \InvalidArgumentException(
'Unable to convert range to list of values with empty string.', 1291234985);
223 $rangeArray = explode(
'-', $range);
225 foreach ($rangeArray as $fieldNumber => $fieldValue) {
227 throw new \InvalidArgumentException(
'Unable to convert value to integer.', 1291237668);
229 $rangeArray[$fieldNumber] = (int)$fieldValue;
232 $rangeArrayCount = count($rangeArray);
233 if ($rangeArrayCount === 1) {
234 $resultList = $rangeArray[0];
235 } elseif ($rangeArrayCount === 2) {
236 $left = $rangeArray[0];
237 $right = $rangeArray[1];
238 if ($left > $right) {
239 throw new \InvalidArgumentException(
'Unable to convert range to list: Left integer must not be greater than right integer.', 1291237145);
241 $resultListArray = [];
242 for ($i = $left; $i <= $right; $i++) {
243 $resultListArray[] = $i;
245 $resultList = implode(
',', $resultListArray);
247 throw new \InvalidArgumentException(
'Unable to convert range to list of values.', 1291234986);
249 return (
string)$resultList;
264 if ($stepExpression ===
'') {
265 throw new \InvalidArgumentException(
'Unable to convert step values.', 1291234987);
267 $stepValuesAndStepArray = explode(
'/', $stepExpression);
268 $stepValuesAndStepArrayCount = count($stepValuesAndStepArray);
269 if ($stepValuesAndStepArrayCount < 1 || $stepValuesAndStepArrayCount > 2) {
270 throw new \InvalidArgumentException(
'Unable to convert step values: Multiple slashes found.', 1291242168);
272 $left = $stepValuesAndStepArray[0] ??
'';
273 $right = $stepValuesAndStepArray[1] ??
'';
275 throw new \InvalidArgumentException(
'Unable to convert step values: Left part of / is empty.', 1291414955);
278 throw new \InvalidArgumentException(
'Unable to convert step values: Right part of / is empty.', 1291414956);
281 throw new \InvalidArgumentException(
'Unable to convert step values: Right part must be a single integer.', 1291414957);
283 $right = (int)$right;
284 $leftArray = explode(
',', $left);
286 $currentStep = $right;
287 foreach ($leftArray as $leftValue) {
289 throw new \InvalidArgumentException(
'Unable to convert step values: Left part must be a single integer or comma separated list of integers.', 1291414958);
291 if ($currentStep === 0) {
292 $currentStep = $right;
294 if ($currentStep === $right) {
295 $validValues[] = (int)$leftValue;
299 if (empty($validValues)) {
300 throw new \InvalidArgumentException(
'Unable to convert step values: Result value list is empty.', 1291414959);
302 return implode(
',', $validValues);
315 return (
string)$expression;
328 $timestamp = strtotime(
'2010-' . $month .
'-01');
330 if (!$timestamp || $timestamp < strtotime(
'2010-01-01') || $timestamp > strtotime(
'2010-12-01')) {
331 throw new \InvalidArgumentException(
'Unable to convert given month name.', 1291083486);
333 return (
int)date(
'n', $timestamp);
346 $normalizedWeekday =
false;
348 if ((
string)$weekday ===
'0') {
351 if ($weekday >= 1 && $weekday <= 7) {
352 $normalizedWeekday = (int)$weekday;
354 if (!$normalizedWeekday) {
356 $timestamp = strtotime(
'next ' . $weekday, mktime(0, 0, 0, 1, 1, 2010));
357 if (!$timestamp || $timestamp < strtotime(
'2010-01-01') || $timestamp > strtotime(
'2010-01-08')) {
358 throw new \InvalidArgumentException(
'Unable to convert given weekday name.', 1291163589);
360 $normalizedWeekday = (int)date(
'N', $timestamp);
362 return $normalizedWeekday;