-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation to cron expression components
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Illuminate/Console/Scheduling/ValidatesFrequencies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console\Scheduling; | ||
|
||
use InvalidArgumentException; | ||
|
||
use const Illuminate\Support\Date\{DAYS_PER_WEEK, HOURS_PER_DAY, MONTHS_PER_YEAR}; | ||
|
||
trait ValidatesFrequencies | ||
{ | ||
/** | ||
* @param int $hours | ||
*/ | ||
protected function validateHour(int $hour) | ||
{ | ||
if ($hour < 0 || $hour > HOURS_PER_DAY) { | ||
throw new InvalidArgumentException("Hour cron expression component must be between 0 and " . HOURS_PER_DAY . ". [$hour] given"); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $dayOfWeek | ||
*/ | ||
protected function validateDayOfWeek(int $dayOfWeek) | ||
{ | ||
if ($dayOfWeek < 0 || $dayOfWeek > DAYS_PER_WEEK) { | ||
throw new InvalidArgumentException("Day of week cron expression component must be between 0 and " . DAYS_PER_WEEK . ". [$dayOfWeek] given"); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $month | ||
*/ | ||
protected function validateMonth(int $month) | ||
{ | ||
if ($month < 0 || $month > MONTHS_PER_YEAR) { | ||
throw new InvalidArgumentException("Month cron expression component must be between 0 and " . MONTHS_PER_YEAR . ". [$month] given"); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $month | ||
*/ | ||
protected function validateDayOfMonth(int $dayOfMonth) | ||
{ | ||
if ($month < 0 || $month > MONTHS_PER_YEAR) { | ||
throw new InvalidArgumentException("Month cron expression component must be between 0 and " . MONTHS_PER_YEAR . ". [$month] given"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support\Date; | ||
|
||
if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_MINUTE'))) { | ||
define(__NAMESPACE__.'\\'.$constant, 60); | ||
} | ||
|
||
if (! defined(__NAMESPACE__.'\\'.($constant = 'MINUTES_PER_HOUR'))) { | ||
define(__NAMESPACE__.'\\'.$constant, 60); | ||
} | ||
|
||
if (! defined(__NAMESPACE__.'\\'.($constant = 'HOURS_PER_DAY'))) { | ||
define(__NAMESPACE__.'\\'.$constant, 24); | ||
} | ||
|
||
if (! defined(__NAMESPACE__.'\\'.($constant = 'DAYS_PER_WEEK'))) { | ||
define(__NAMESPACE__.'\\'.$constant, 7); | ||
} | ||
|
||
if (! defined(__NAMESPACE__.'\\'.($constant = 'MONTHS_PER_YEAR'))) { | ||
define(__NAMESPACE__.'\\'.$constant, 12); | ||
} |