PHP Class PMA\libraries\config\Validator

Validation function takes two argument: id for which it is called and array of fields' values (usually values for entire formset, as defined in forms.inc.php). 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).
Show file Open project: phpmyadmin/phpmyadmin Class Usage Examples

Public Methods

Method Description
getValidators ( PMA\libraries\config\ConfigFile $cf ) : array Returns validator list
testDBConnection ( string $connect_type, string $host, string $port, string $socket, string $user, string $pass = null, string $error_key = 'Server' ) : boolean | array Test database connection
validate ( PMA\libraries\config\ConfigFile $cf, string | array $validator_id, &$values, boolean $isPostSource ) : boolean | array Runs validation $validator_id on values $values and returns error list.
validateByRegex ( string $path, array $values, string $regex ) : array Validates value according to given regular expression Pattern and modifiers must be a valid for PCRE and JavaScript RegExp
validateNonNegativeNumber ( string $path, array $values ) : array Validates non-negative number
validateNumber ( string $path, array $values, boolean $allow_neg, boolean $allow_zero, integer $max_value, string $error_string ) : string Tests integer value
validatePMAStorage ( string $path, array $values ) : array Validate pmadb config
validatePortNumber ( string $path, array $values ) : array Validates port number
validatePositiveNumber ( string $path, array $values ) : array Validates positive number
validateRegex ( string $path, array $values ) : array Validates regular expression
validateServer ( string $path, array $values ) : array Validate server config
validateTrustedProxies ( string $path, array $values ) : array Validates TrustedProxies field
validateUpperBound ( string $path, array $values, integer $max_value ) : array Validates upper bound for numeric inputs

Method Details

getValidators() public static method

Returns validator list
public static getValidators ( PMA\libraries\config\ConfigFile $cf ) : array
$cf PMA\libraries\config\ConfigFile Config file instance
return array

testDBConnection() public static method

Test database connection
public static testDBConnection ( string $connect_type, string $host, string $port, string $socket, string $user, string $pass = null, string $error_key = 'Server' ) : boolean | array
$connect_type string 'tcp' or 'socket'
$host string host name
$port string tcp port to use
$socket string socket to use
$user string username to use
$pass string password to use
$error_key string key to use in return array
return boolean | array

validate() public static method

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
public static validate ( PMA\libraries\config\ConfigFile $cf, string | array $validator_id, &$values, boolean $isPostSource ) : boolean | array
$cf PMA\libraries\config\ConfigFile Config file instance
$validator_id string | array ID of validator(s) to run
$isPostSource boolean tells whether $values are directly from POST request
return boolean | array

validateByRegex() public static method

Validates value according to given regular expression Pattern and modifiers must be a valid for PCRE and JavaScript RegExp
public static validateByRegex ( string $path, array $values, string $regex ) : array
$path string path to config
$values array config values
$regex string regular expression to match
return array

validateNonNegativeNumber() public static method

Validates non-negative number
public static validateNonNegativeNumber ( string $path, array $values ) : array
$path string path to config
$values array config values
return array

validateNumber() public static method

Tests integer value
public static validateNumber ( string $path, array $values, boolean $allow_neg, boolean $allow_zero, integer $max_value, string $error_string ) : string
$path string path to config
$values array config values
$allow_neg boolean allow negative values
$allow_zero boolean allow zero
$max_value integer max allowed value
$error_string string error message key: $GLOBALS["strConfig$error_lang_key"]
return string empty string if test is successful

validatePMAStorage() public static method

Validate pmadb config
public static validatePMAStorage ( string $path, array $values ) : array
$path string path to config, not used keep this parameter since the method is invoked using reflection along with other similar methods
$values array config values
return array

validatePortNumber() public static method

Validates port number
public static validatePortNumber ( string $path, array $values ) : array
$path string path to config
$values array config values
return array

validatePositiveNumber() public static method

Validates positive number
public static validatePositiveNumber ( string $path, array $values ) : array
$path string path to config
$values array config values
return array

validateRegex() public static method

Validates regular expression
public static validateRegex ( string $path, array $values ) : array
$path string path to config
$values array config values
return array

validateServer() public static method

Validate server config
public static validateServer ( string $path, array $values ) : array
$path string path to config, not used keep this parameter since the method is invoked using reflection along with other similar methods
$values array config values
return array

validateTrustedProxies() public static method

Validates TrustedProxies field
public static validateTrustedProxies ( string $path, array $values ) : array
$path string path to config
$values array config values
return array

validateUpperBound() public static method

Validates upper bound for numeric inputs
public static validateUpperBound ( string $path, array $values, integer $max_value ) : array
$path string path to config
$values array config values
$max_value integer maximal allowed value
return array