Documentation

RulesClassValidator
in package
implements RulesValidatorInterface

Rules based validation processor.

This loads a set of default RuleInterface rules from the config/rules.php file.

Table of Contents

Interfaces

RulesValidatorInterface
This class is a validator that uses rules.

Properties

$data  : array<string|int, mixed>|object
$errors  : array<string|int, mixed>
$original_rules  : array<string|int, mixed>
A copy of the original rulesets, used for reparsing rules.
$rules  : array<string|int, RuleInterface>
Active rules, a subset of the validators as determined by setRules().
$validators  : array<string|int, RuleInterface>
Available rules, as installed by setValidators().

Methods

__construct()  : mixed
addFieldError()  : void
Add an error message for a given field to the field errors list
addMultipleFieldError()  : void
Add an error message from a multiple-field validation (e.g. checking at least one is set)
addValidator()  : void
errorsAsArray()  : array<string|int, string>
Return all errors as a mapped array.
fromValidationException()  : void
Populates form field errors from ValidationException
getErrors()  : array<string, array<string|int, mixed>>
Get valdiation errors.
hasErrors()  : bool
Does this object have validation errors?
parseRule()  : RuleInterface
refreshRules()  : void
required()  : void
Checks various fields are required If a field is required and no value is provided, no other validation will be proessed for that field.
setData()  : void
Update the data to validate
setFieldValue()  : void
Set the value for a single data field
setRules()  : void
setValidators()  : void
validate()  : bool
Perform validations.

Properties

$original_rules

A copy of the original rulesets, used for reparsing rules.

protected array<string|int, mixed> $original_rules = []

Methods

__construct()

public __construct(array<string|int, mixed>|object $data) : mixed
Parameters
$data : array<string|int, mixed>|object

Data to validate

addFieldError()

Add an error message for a given field to the field errors list

public addFieldError(string $field_name, string|array<string|int, string> $message) : void
Parameters
$field_name : string

The field to add the error message for

$message : string|array<string|int, string>

The message text

addMultipleFieldError()

Add an error message from a multiple-field validation (e.g. checking at least one is set)

public addMultipleFieldError(array<string|int, mixed> $fields, string $message) : void
Parameters
$fields : array<string|int, mixed>

The fields to add the error message for

$message : string

The message text

addValidator()

public addValidator(array<string|int, mixed>|class-string|RuleInterface $validator[, null|string $name = null ]) : void
Parameters
$validator : array<string|int, mixed>|class-string|RuleInterface
$name : null|string = null

override

Tags
throws
InvalidArgumentException

errorsAsArray()

Return all errors as a mapped array.

public errorsAsArray() : array<string|int, string>
Return values
array<string|int, string> —

[ 'label' => 'messages' ]

getErrors()

Get valdiation errors.

public getErrors() : array<string, array<string|int, mixed>>
Tags
inheritdoc
Return values
array<string, array<string|int, mixed>> —

[ item => [errors] ]

hasErrors()

Does this object have validation errors?

public hasErrors() : bool
Tags
inheritdoc
Return values
bool

parseRule()

public parseRule(string $name, array<string|int, mixed> $ruleset) : RuleInterface
Parameters
$name : string
$ruleset : array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
RuleInterface

required()

Checks various fields are required If a field is required and no value is provided, no other validation will be proessed for that field.

public required(array<string|int, mixed> $fields) : void
Parameters
$fields : array<string|int, mixed>

Fields to check

setData()

Update the data to validate

public setData(array<string|int, mixed>|object $data) : void
Parameters
$data : array<string|int, mixed>|object

Data to validate

setFieldValue()

Set the value for a single data field

public setFieldValue(string $field, mixed $value) : void
Parameters
$field : string

The field to set

$value : mixed

The value to set on the field

setRules()

public setRules(array<string|int, mixed> $rules) : void
Parameters
$rules : array<string|int, mixed>
Tags
inheritdoc

setValidators()

public setValidators(array<string|int, mixed> $validators) : void
Parameters
$validators : array<string|int, mixed>
Tags
throws
InvalidArgumentException

validate()

Perform validations.

public validate() : bool
Tags
inheritdoc
Return values
bool —

true if valid, false otherwise

On this page

Search results