NormalizeCommand

Validate and normalize a cron command.

Special fields like three letter weekdays, ranges and steps are substituted to a comma separated list of integers. Example: '2-4 10-40/10 * mar * fri' will be normalized to '2,4 10,20,30,40 * * 3 1,2'

Internal

not part of TYPO3 Public API

Table of Contents

Methods

normalize()  : string
Main API method: Get the cron command and normalize it.
convertKeywordsToCronCommand()  : string
Accept special cron command keywords and convert to standard cron syntax.
convertRangeToListOfValues()  : string
Convert a range of integers to a list: 4-6 results in a string '4,5,6'
normalizeFields()  : string
Normalize cron command field to list of integers or *
normalizeIntegerField()  : string
Normalize integer field.
normalizeMonth()  : int
Accept a string representation or integer number of a month like 'jan', 'February', 01, ... and convert to normalized integer value between 1 and 12
normalizeMonthAndWeekday()  : string
Dispatcher method for normalizeMonth and normalizeWeekday
normalizeMonthAndWeekdayField()  : string
Normalize month field.
normalizeWeekday()  : int
Accept a string representation or integer number of a weekday like 'mon', 'Friday', 3, ... and convert to normalized integer value between 1 and 7
reduceListOfValuesByStepValue()  : string
Reduce a given list of values by step value.
splitFields()  : array<string|int, mixed>
Split a given cron command like '23 * * * *' to an array with five fields.

Methods

normalize()

Main API method: Get the cron command and normalize it.

public static normalize(string $cronCommand) : string

If no exception is thrown, the resulting cron command is validated and consists of five whitespace separated fields, which are either the letter '*' or a sorted, unique comma separated list of integers.

Parameters
$cronCommand : string

The cron command to normalize

Tags
throws
InvalidArgumentException

cron command is invalid or out of bounds

Return values
string

Normalized cron command

convertKeywordsToCronCommand()

Accept special cron command keywords and convert to standard cron syntax.

protected static convertKeywordsToCronCommand(string $cronCommand) : string

Allowed keywords: @yearly, @annually, @monthly, @weekly, @daily, @midnight, @hourly

Parameters
$cronCommand : string

Cron command

Return values
string

Normalized cron command if keyword was found, else unchanged cron command

convertRangeToListOfValues()

Convert a range of integers to a list: 4-6 results in a string '4,5,6'

protected static convertRangeToListOfValues(string $range) : string
Parameters
$range : string

Integer-integer

Tags
throws
InvalidArgumentException

If range can not be converted to list

Return values
string

normalizeFields()

Normalize cron command field to list of integers or *

protected static normalizeFields(string $cronCommand) : string
Parameters
$cronCommand : string

cron command

Return values
string

Normalized cron command

normalizeIntegerField()

Normalize integer field.

protected static normalizeIntegerField(string $expression[, int $lowerBound = 0 ][, int $upperBound = 59 ]) : string
Parameters
$expression : string

Expression

$lowerBound : int = 0

Lower limit of result list

$upperBound : int = 59

Upper limit of result list

Tags
throws
InvalidArgumentException

If field is invalid or out of bounds

Return values
string

Normalized expression

normalizeMonth()

Accept a string representation or integer number of a month like 'jan', 'February', 01, ... and convert to normalized integer value between 1 and 12

protected static normalizeMonth(string $month) : int
Parameters
$month : string

Month representation

Tags
throws
InvalidArgumentException

If month string can not be converted to integer

Return values
int

normalizeMonthAndWeekday()

Dispatcher method for normalizeMonth and normalizeWeekday

protected static normalizeMonthAndWeekday(string $expression[, bool $isMonth = true ]) : string
Parameters
$expression : string

Month or weekday to be normalized

$isMonth : bool = true

TRUE if a month is handled, FALSE for weekday

Return values
string

normalized month or weekday

normalizeMonthAndWeekdayField()

Normalize month field.

protected static normalizeMonthAndWeekdayField(string $expression[, bool $isMonthField = true ]) : string
Parameters
$expression : string

Month field expression

$isMonthField : bool = true

TRUE if month field is handled, FALSE for weekday field

Return values
string

Normalized expression

normalizeWeekday()

Accept a string representation or integer number of a weekday like 'mon', 'Friday', 3, ... and convert to normalized integer value between 1 and 7

protected static normalizeWeekday(string $weekday) : int
Parameters
$weekday : string

Weekday representation

Tags
throws
InvalidArgumentException

If weekday string can not be converted

Return values
int

reduceListOfValuesByStepValue()

Reduce a given list of values by step value.

protected static reduceListOfValuesByStepValue(string $stepExpression) : string

Following a range with ``/'' specifies skips of the number's value through the range. 1-5/2 -> 1,3,5 2-10/3 -> 2,5,8

Parameters
$stepExpression : string

Step value expression

Tags
throws
InvalidArgumentException

if step value is invalid or if resulting list is empty

Return values
string

Comma separated list of valid values

splitFields()

Split a given cron command like '23 * * * *' to an array with five fields.

protected static splitFields(string $cronCommand) : array<string|int, mixed>
Parameters
$cronCommand : string

cron command

Tags
throws
InvalidArgumentException

If splitted array does not contain five entries

Return values
array<string|int, mixed>

        
On this page

Search results