AbstractValidator
in package
implements
Validator
uses
Log
Validator is a singleton base class for classes validating DomainObjects.
Table of Contents
Interfaces
Properties
- $instance : Validator
- Stores the single instance of Validator.
- $validators : array<string|int, callable>
- Needs to be declared in every childclass
Methods
- addValidator() : mixed
- Dynamically add a validator function
- getInstance() : Validator
- Returnst the instances of the validator, instantiates a new one if there isn't one already.
- getValidators() : mixed
- Returns the validator functions.
- removeValidator() : mixed
- Dynamiocally remove a validator function
- validate() : ResultCollection|bool
- Validates a DomainObject.
- __construct() : mixed
- Implement constructor in childclasses and assign the validator functions to using setValidators() All sub-classes should have protected constructors.
- setValidators() : mixed
- Sets the validator functions.
Properties
$instance
Stores the single instance of Validator.
protected
static Validator
$instance
Tags
$validators
Needs to be declared in every childclass
protected
array<string|int, callable>
$validators
= []
A list of tests used to validate domainObjects dataTypes, indexed by fieldname
Methods
addValidator()
Dynamically add a validator function
public
addValidator(string $field, callable $validator[, string $validatorIndex = null ]) : mixed
Parameters
- $field : string
-
The DomainObject Field to validate
- $validator : callable
-
The Validator function to use
- $validatorIndex : string = null
-
The internal index used to store the validator function. Use this to remove or overwrite the validator
getInstance()
Returnst the instances of the validator, instantiates a new one if there isn't one already.
public
static getInstance() : Validator
Return values
ValidatorgetValidators()
Returns the validator functions.
public
getValidators() : mixed
removeValidator()
Dynamiocally remove a validator function
public
removeValidator(string $field[, mixed $validatorIndex = null ]) : mixed
Parameters
- $field : string
- $validatorIndex : mixed = null
validate()
Validates a DomainObject.
public
validate(DomainObject $domainObject) : ResultCollection|bool
Parameters
- $domainObject : DomainObject
Return values
ResultCollection|bool —returns true if validations passed a ResultCollection otherwise
__construct()
Implement constructor in childclasses and assign the validator functions to using setValidators() All sub-classes should have protected constructors.
protected
abstract __construct() : mixed
setValidators()
Sets the validator functions.
protected
setValidators(mixed $tests) : mixed
Parameters
- $tests : mixed