Aplus Framework Docs

Validation
in package

Class Validation.

Table of Contents

$debugCollector  : ValidationCollector
$errors  : array<string|int, mixed>
The last errors.
$labels  : array<string|int, mixed>
The labels used to replace field names.
$language  : Language
The Language instance.
$messages  : array<string|int, mixed>
Custom error messages.
$rules  : array<string|int, mixed>
The Validator rules.
$validators  : array<string|int, mixed>
The current Validators.
__construct()  : mixed
Validation constructor.
getDebugCollector()  : ValidationCollector|null
getError()  : string|null
Get latest error for a given field.
getErrors()  : array<string, string>
Get latest errors.
getFilledMessage()  : string
getLabel()  : string|null
Get the label for a given field.
getLabels()  : array<string, string>
Get a list of all labels.
getLanguage()  : Language
getMessage()  : string|null
Get the custom error message from a field rule.
getMessages()  : array<string, array<string, string>>
Get all custom error messages set.
getRules()  : array<string, array<int, array<string, array|string>>>
Get a list of current rules.
getRuleset()  : array<string|int, mixed>
getValidators()  : array<int, \Framework\Validation\Validator|string>
hasError()  : bool
isRuleAvailable()  : bool
Tells if a rule is available in the current validators.
reset()  : static
Reset the validation.
setDebugCollector()  : static
setError()  : static
setLabel()  : static
Set label for a field.
setLabels()  : static
Set fields labels.
setLanguage()  : static
setMessage()  : static
Set a custom error message for a field rule.
setMessages()  : static
Set many custom error messages.
setRule()  : static
Set rules for a given field.
setRules()  : static
Set field rules.
validate()  : bool
Validate data with all rules.
validateOnly()  : bool
Validate only fields set on data.
escapeArgs()  : array<string|int, string>
extractRules()  : array<int, array<string, array|string>>
parseRule()  : array<string, array|string>
replaceArgs()  : array<string|int, mixed>
Replace argument placeholders with data values.
run()  : bool
setEqualsField()  : array<string, mixed>
validateField()  : bool
validateOnlySet()  : bool
validateRule()  : bool

Properties

$errors

The last errors.

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

The field names as keys and the rule and arguments as values

$labels

The labels used to replace field names.

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

The field names as keys and the labels as values

$messages

Custom error messages.

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

The field name as keys and an associative array of rule names as keys and messages as values

$rules

The Validator rules.

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

The field names as keys and the rules and arguments as values

$validators

The current Validators.

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

Values are the Validators FQCN or instances

Methods

__construct()

Validation constructor.

public __construct([array<int, \Framework\Validation\Validator|string>|null $validators = null ][, Language|null $language = null ]) : mixed
Parameters
$validators : array<int, \Framework\Validation\Validator|string>|null = null
$language : Language|null = null
Return values
mixed

getError()

Get latest error for a given field.

public getError(string $field) : string|null
Parameters
$field : string
Return values
string|null

getErrors()

Get latest errors.

public getErrors() : array<string, string>
Return values
array<string, string>

getFilledMessage()

public getFilledMessage(string $field, string $rule[, array<string|int, mixed> $args = [] ]) : string
Parameters
$field : string
$rule : string
$args : array<string|int, mixed> = []
Return values
string

getLabel()

Get the label for a given field.

public getLabel(string $field) : string|null
Parameters
$field : string
Return values
string|null

getLabels()

Get a list of all labels.

public getLabels() : array<string, string>
Return values
array<string, string>

getMessage()

Get the custom error message from a field rule.

public getMessage(string $field, string $rule) : string|null
Parameters
$field : string

The field name

$rule : string

The rule name

Return values
string|null

The message string or null if the message is not set

getMessages()

Get all custom error messages set.

public getMessages() : array<string, array<string, string>>
Return values
array<string, array<string, string>>

getRules()

Get a list of current rules.

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

getRuleset()

public getRuleset() : array<string|int, mixed>
Return values
array<string|int, mixed>

getValidators()

public getValidators() : array<int, \Framework\Validation\Validator|string>
Return values
array<int, \Framework\Validation\Validator|string>

hasError()

public hasError(string $field) : bool
Parameters
$field : string
Return values
bool

isRuleAvailable()

Tells if a rule is available in the current validators.

public isRuleAvailable(string $rule) : bool
Parameters
$rule : string
Return values
bool

reset()

Reset the validation.

public reset() : static
Return values
static

setError()

public setError(string $field, string $rule[, array<int, string> $args = [] ]) : static
Parameters
$field : string
$rule : string
$args : array<int, string> = []
Return values
static

setLabel()

Set label for a field.

public setLabel(string $field, string $label) : static
Parameters
$field : string
$label : string
Return values
static

setLabels()

Set fields labels.

public setLabels(array<string, string> $labels) : static
Parameters
$labels : array<string, string>

An associative array with fields as keys and label as values

Return values
static

setLanguage()

public setLanguage([Language|null $language = null ]) : static
Parameters
$language : Language|null = null
Return values
static

setMessage()

Set a custom error message for a field rule.

public setMessage(string $field, string $rule, string $message) : static
Parameters
$field : string

The field name

$rule : string

The field rule name

$message : string

The custom error message for the field rule

Return values
static

setMessages()

Set many custom error messages.

public setMessages(array<string, array<string, string>> $messages) : static
Parameters
$messages : array<string, array<string, string>>

A multi-dimensional array with field names as keys and values as arrays where the keys are rule names and values are the custom error message strings

Return values
static

setRule()

Set rules for a given field.

public setRule(string $field, array<string|int, string>|string $rules) : static
Parameters
$field : string
$rules : array<string|int, string>|string
Return values
static

setRules()

Set field rules.

public setRules(array<string, string[]|string> $rules) : static
Parameters
$rules : array<string, string[]|string>

An associative array with field as keys and values as rules

Return values
static

validate()

Validate data with all rules.

public validate(array<string, mixed> $data) : bool
Parameters
$data : array<string, mixed>
Return values
bool

validateOnly()

Validate only fields set on data.

public validateOnly(array<string, mixed> $data) : bool
Parameters
$data : array<string, mixed>
Return values
bool

escapeArgs()

protected escapeArgs(array<string|int, string> $args) : array<string|int, string>
Parameters
$args : array<string|int, string>
Return values
array<string|int, string>

extractRules()

protected extractRules(string $rules) : array<int, array<string, array|string>>
Parameters
$rules : string
Return values
array<int, array<string, array|string>>

parseRule()

protected parseRule(string $rule) : array<string, array|string>
Parameters
$rule : string
Return values
array<string, array|string>

replaceArgs()

Replace argument placeholders with data values.

protected replaceArgs(array<string|int, mixed> $args, array<string, mixed> $data) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>
$data : array<string, mixed>
Return values
array<string|int, mixed>

run()

protected run(array<string, array<string|int, mixed>> $fieldRules, array<string, mixed> $data) : bool
Parameters
$fieldRules : array<string, array<string|int, mixed>>
$data : array<string, mixed>
Return values
bool

setEqualsField()

protected setEqualsField(array<string, mixed> $rule) : array<string, mixed>
Parameters
$rule : array<string, mixed>
Return values
array<string, mixed>

validateField()

protected validateField(string $field, array<string, array<string|int, mixed>> $rules, array<string, mixed> $data) : bool
Parameters
$field : string
$rules : array<string, array<string|int, mixed>>
$data : array<string, mixed>
Tags
since
2.2

Added "blank", "null" and "empty" rules

Return values
bool

validateOnlySet()

protected validateOnlySet(array<string, mixed> $data) : bool
Parameters
$data : array<string, mixed>
Return values
bool

validateRule()

protected validateRule(string $rule, string $field, array<int|string, mixed> $args, array<string, mixed> $data) : bool
Parameters
$rule : string
$field : string
$args : array<int|string, mixed>
$data : array<string, mixed>
Return values
bool

Search results