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
Tags
throws
InvalidArgumentException

cron command is invalid or out of bounds

Return values
string

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
Return values
string

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
Return values
string

normalizeIntegerField()

Normalize integer field.

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

If field is invalid or out of bounds

Return values
string

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
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
$isMonth : bool = true
Return values
string

normalizeMonthAndWeekdayField()

Normalize month field.

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

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
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
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
Tags
throws
InvalidArgumentException

If splitted array does not contain five entries

Return values
array<string|int, mixed>

        
On this page

Search results