SPHPlayground API
SPHPlayground
sphplayground sphplayground

Validator aggregates

The ValidatorChain validator

The ValidatorChain is an aggregation of Validator objects. It validates the given input against all of its inner validators and the input is valid only if it passes all of them.

Synopsis
Constructs a new validator
public __construct(bool $breaksOnFailure = true)
Magic call method
public __call(string $name, array $arguments):Validator
public breaksOnFailure():bool
public __invoke(mixed $value):bool
Validates given value
public isValid(mixed $value):bool
Appends a new validator(s) to the chain
public appendValidators(Validator ... $validator):static
Returns error messages
public getErrors():MessageContainer
Counts the number of the Validator objects in the chain
public count():int
inserts a new Regexp validator
public collectionLength(?int $min = 'null', ?int $max = 'null'): CollectionLength
inserts a new Regexp validator
public regex(mixed $content = 'null', mixed $for = 'null'): Regex
public whitelist(array $haystack, string $defaultErrorMessage): Whitelist
public notEmpty(string $message = '\'Value is empty\''): NotEmpty
public email(string $errorMessage = '\'Email address is invalid\''): Email
;
public isInstanceOf(string $className, string $error = '\'Value is not instance of :instance\''): IsInstanceOf

The ArrayValidator validator

A ArrayValidator is an aggregate of validators validating user inputs data provided by HTML forms. A ArrayValidator can validate PHP's native arrays and just about any kind of Traversable data containing key value pairs.

Synopsis
ID for invalid map data type error message
public const string NOT_MAP_DATA
ID for default error message
public const string INVALID
Constructs a new validator
public __construct(string $message = 'Dataset contains invalid values')
Validates given value
public isValid(mixed $value):bool
Checks whether any validators exists for the input name
public hasValidator(string $inputName):bool
Returns the validator object of the named input value
public getValidator(string $inputName):?Validator
Sets a validator object for the named input value
public setValidator(string $inputName, Validator $validator):static
Unsets a named validator object
public unsetValidator(string $inputName):static
Invoke validator as a command
public __invoke(mixed $value):bool
public setErrorTemplate(string|int $id, TemplateInterface|string $template):void
Returns error messages
public getErrors():MessageContainer