flexic / cron-builder
Builder for cronjob expressions.
1.0.0
2023-01-06 14:36 UTC
Requires
- php: ^8.1
Requires (Dev)
- ergebnis/php-cs-fixer-config: ^4.9.0
- phpstan/phpstan: ^1.8.8
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.4.4
- phpunit/phpunit: ^9.5.26
README
This package provides a builder for cron expressions.
Installation
composer require flexic/cron-builder
Usage
use Flexic\CronBuilder\CronBuilder; $cron = CronBuilder::create() ->everyMinute() ->build(); // * * * * * $cron = CronBuilder::create() ->atMinuteInterval(5) ->build(); // */5 * * * * $cron = CronBuilder::create() ->notOnDaysOfWeek(3, 4) ->build(); // * * * * 1,2,5,6,0
The builder returns an object of type Flexic\CronBuilder\Cron
. This object allows to get the complete cron or only parts of it.
It can also be converted to a string.
Methods
Builder
Method | Description |
---|---|
create() | Creates a new instance of the builder. (Method is static called) |
build() | Builds the cron expression. |
everyMinute() | |
atMinuteInterval($interval) | |
atMinute($minute) | |
atMinutes($minutes) | |
betweenMinutes($from, $to) | |
everyHour() | |
atHourInterval($interval) | |
atHour($hour) | |
atHours($hours) | |
notAtHours($hours) | |
betweenHours($from, $to) | |
everyDay() | |
onDayInterval($interval) | |
onDay($day) | |
onDays($days) | |
betweenDays($from, $to) | |
inJanuary() | |
inFebruary() | |
inMarch() | |
inApril() | |
inMay() | |
inJune() | |
inJuly() | |
inAugust() | |
inSeptember() | |
inOctober() | |
inNovember() | |
inDecember() | |
inMonth($month) | |
everyMonth() | |
onMonthInterval($interval) | |
onSunday() | |
onMonday() | |
onTuesday() | |
onWednesday() | |
onThursday() | |
onFriday() | |
onSaturday() | |
onDayOfWeek($weekday) | |
onDaysOfWeek($weekdays) | |
betweenDaysOfWeek($from, $to) | |
notOnDaysOfWeek($weekdays) | |
onWeekend() | |
onWeekdays() | |
everyWeekday() | |
onWeekdayInterval($interval) | |
hourly() | |
hourlyAt($minute) | |
daily() | |
weekly() | |
monthly() | |
quarterly() | |
yearly() |
Cron
Method | Description | Return Format |
---|---|---|
getCron() | Returns the complete cron expression | string |
getMinuteExpression() | Returns the minute expression | Expression Object |
getHourExpression() | Returns the hour expression | Expression Object |
getDayOfMonthExpression() | Returns the day of month expression | Expression Object |
getMonthExpression() | Returns the month expression | Expression Object |
getDayOfWeekExpression() | Returns the day of week expression | Expression Object |
__toString() | Returns the complete cron expression | string |
Lexer
Lexer is used to parse the cron expression into tokens.
Method | Description | Return Format |
---|---|---|
fromString() | Parses the cron expression into tokens | Cron Object |