class Validator (View source)

Validation class for various validation functions

Validation function takes two argument: id for which it is called and array of fields' values (usually values for entire formset). The function must always return an array with an error (or error array) assigned to a form element (formset name or field path). Even if there are no errors, key must be set with an empty value.

Validation functions are assigned in $cfg_db['_validators'] (config.values.php).

Methods

static array
getValidators(ConfigFile $cf)

Returns validator list

static bool|array
validate(ConfigFile $cf, string|array $validatorId, array $values, bool $isPostSource)

Runs validation $validator_id on values $values and returns error list.

static bool|array
testDBConnection(string $host, string $port, string $socket, string $user, string $pass, string $errorKey = 'Server')

Test database connection

static array
validateServer(string $path, array $values)

Validate server config

static array
validatePMAStorage(string $path, array $values)

Validate pmadb config

static array
validateRegex(string $path, array $values)

Validates regular expression

static array
validateTrustedProxies(string $path, array $values)

Validates TrustedProxies field

static string
validateNumber(string $path, array $values, bool $allowNegative, bool $allowZero, int $maxValue, string $errorString)

Tests integer value

static array
validatePortNumber(string $path, array $values)

Validates port number

static array
validatePositiveNumber(string $path, array $values)

Validates positive number

static array
validateNonNegativeNumber(string $path, array $values)

Validates non-negative number

static array|string
validateByRegex(string $path, array $values, string $regex)

Validates value according to given regular expression Pattern and modifiers must be a valid for PCRE and JavaScript RegExp

static array
validateUpperBound(string $path, array $values, int $maxValue)

Validates upper bound for numeric inputs

Details

static array getValidators(ConfigFile $cf)

Returns validator list

Parameters

ConfigFile $cf

Config file instance

Return Value

array

static bool|array validate(ConfigFile $cf, string|array $validatorId, array $values, bool $isPostSource)

Runs validation $validator_id on values $values and returns error list.

Return values: o array, keys - field path or formset id, values - array of errors when $isPostSource is true values is an empty array to allow for error list cleanup in HTML document o false - when no validators match name(s) given by $validator_id

Parameters

ConfigFile $cf

Config file instance

string|array $validatorId

ID of validator(s) to run

array $values

Values to validate

bool $isPostSource

tells whether $values are directly from POST request

Return Value

bool|array

static bool|array testDBConnection(string $host, string $port, string $socket, string $user, string $pass, string $errorKey = 'Server')

Test database connection

Parameters

string $host

host name

string $port

tcp port to use

string $socket

socket to use

string $user

username to use

string $pass

password to use

string $errorKey

key to use in return array

Return Value

bool|array

static array validateServer(string $path, array $values)

Validate server config

Parameters

string $path

path to config, not used keep this parameter since the method is invoked using reflection along with other similar methods

array $values

config values

Return Value

array

static array validatePMAStorage(string $path, array $values)

Validate pmadb config

Parameters

string $path

path to config, not used keep this parameter since the method is invoked using reflection along with other similar methods

array $values

config values

Return Value

array

static array validateRegex(string $path, array $values)

Validates regular expression

Parameters

string $path

path to config

array $values

config values

Return Value

array

static array validateTrustedProxies(string $path, array $values)

Validates TrustedProxies field

Parameters

string $path

path to config

array $values

config values

Return Value

array

static string validateNumber(string $path, array $values, bool $allowNegative, bool $allowZero, int $maxValue, string $errorString)

Tests integer value

Parameters

string $path

path to config

array $values

config values

bool $allowNegative

allow negative values

bool $allowZero

allow zero

int $maxValue

max allowed value

string $errorString

error message string

Return Value

string

empty string if test is successful

static array validatePortNumber(string $path, array $values)

Validates port number

Parameters

string $path

path to config

array $values

config values

Return Value

array

static array validatePositiveNumber(string $path, array $values)

Validates positive number

Parameters

string $path

path to config

array $values

config values

Return Value

array

static array validateNonNegativeNumber(string $path, array $values)

Validates non-negative number

Parameters

string $path

path to config

array $values

config values

Return Value

array

static array|string validateByRegex(string $path, array $values, string $regex)

Validates value according to given regular expression Pattern and modifiers must be a valid for PCRE and JavaScript RegExp

Parameters

string $path

path to config

array $values

config values

string $regex

regular expression to match

Return Value

array|string

static array validateUpperBound(string $path, array $values, int $maxValue)

Validates upper bound for numeric inputs

Parameters

string $path

path to config

array $values

config values

int $maxValue

maximal allowed value

Return Value

array