class Validator

The Validator is used to chain Validators together and validate a set of data with it.

property availableValidators


Holds the available validators.


Creates instances of the available validators.

  • $validators (array) – the validators to load, key = name, value = classname within the namespace “ValdiValidator”
isValidRule($validator, $parameters, $value)

Validates a single rule.

  • $validator (string) – the validator to use
  • $parameters (string[]) – the validation parameters, depending on the validator
  • $value (string) – the value to validate

boolean true if the value is valid



addValidator($name, ValidatorInterface $validator)

Adds additional validator. It can override existing validators as well.

  • $name (string) – the name of the new validator.
  • $validator (ValidatorInterface) – the validator to add
isValidValue($rules, $value)

Validates a value via the given rules.

  • $rules (array) – the validation rules
  • $value (string) – the value to validate

string[] the fields where the validation failed

isValid($rules, $data)

Performs the actual validation.

  • $rules (array) – the validation rules: an array with a field name as key and an array of rules to use for this field; each rule is an array with the validator name as first element and parameters as following elements; example: array(‘a’ => array(array(‘required’)), ‘b’ => array(array(‘min’, 1)))
  • $data (array) – the data to validate as a map

array<string,boolean|array> the validation result having the keys “valid” (true or false) and the key “errors” containing all failed fields as keys with arrays of the failed validator names; example where the field “b” from the above sample failed due to the min validator: array(‘valid’ => false, errors => array(‘b’ => array(‘min’))) the “or” validator doesn’t return a single string on validation error; instead, it returns an array listing all failed validators of it: array(‘or’ => array(‘url’, ‘email’)