Validation
in package
Class Validation.
Table of Contents
Properties
- $debugCollector : ValidationCollector
- $errors : array<string, array<string, array<string, array<int, string>|string>>>
- The last errors.
- $labels : array<string, string>
- The labels used to replace field names.
- $language : Language
- The Language instance.
- $messages : array<string, array<string, string>>
- Custom error messages.
- $rules : array<string, array<int, array<string, array<int, string>|string>>>
- The Validator rules.
- $validators : array<int, Validator|string>
- The current Validators.
Methods
- __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<int, string>|string>>>
- Get a list of current rules.
- getRuleset() : array<string|int, mixed>
- getValidators() : array<int, 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<int, string>|string>>
- parseRule() : array<string, array<int, string>|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
$debugCollector
protected
ValidationCollector
$debugCollector
$errors
The last errors.
protected
array<string, array<string, array<string, array<int, string>|string>>>
$errors
= []
The field names as keys and the rule and arguments as values
$labels
The labels used to replace field names.
protected
array<string, string>
$labels
= []
The field names as keys and the labels as values
$language
The Language instance.
protected
Language
$language
$messages
Custom error messages.
protected
array<string, array<string, string>>
$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, array<int, array<string, array<int, string>|string>>>
$rules
= []
The field names as keys and the rules and arguments as values
$validators
The current Validators.
protected
array<int, Validator|string>
$validators
= []
Values are the Validators FQCN or instances
Methods
__construct()
Validation constructor.
public
__construct([array<int, Validator|string>|null $validators = null ][, Language|null $language = null ]) : mixed
Parameters
getDebugCollector()
public
getDebugCollector() : ValidationCollector|null
Return values
ValidationCollector|nullgetError()
Get latest error for a given field.
public
getError(string $field) : string|null
Parameters
- $field : string
Return values
string|nullgetErrors()
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
stringgetLabel()
Get the label for a given field.
public
getLabel(string $field) : string|null
Parameters
- $field : string
Attributes
- #[Pure]
Return values
string|nullgetLabels()
Get a list of all labels.
public
getLabels() : array<string, string>
Attributes
- #[Pure]
Return values
array<string, string>getLanguage()
public
getLanguage() : Language
Return values
LanguagegetMessage()
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<int, string>|string>>>
Attributes
- #[Pure]
Return values
array<string, array<int, array<string, array<int, string>|string>>>getRuleset()
public
getRuleset() : array<string|int, mixed>
Return values
array<string|int, mixed>getValidators()
public
getValidators() : array<int, Validator|string>
Return values
array<int, Validator|string>hasError()
public
hasError(string $field) : bool
Parameters
- $field : string
Return values
boolisRuleAvailable()
Tells if a rule is available in the current validators.
public
isRuleAvailable(string $rule) : bool
Parameters
- $rule : string
Return values
boolreset()
Reset the validation.
public
reset() : static
Return values
staticsetDebugCollector()
public
setDebugCollector(ValidationCollector $debugCollector) : static
Parameters
- $debugCollector : ValidationCollector
Return values
staticsetError()
public
setError(string $field, string $rule[, array<int, string> $args = [] ]) : static
Parameters
- $field : string
- $rule : string
- $args : array<int, string> = []
Return values
staticsetLabel()
Set label for a field.
public
setLabel(string $field, string $label) : static
Parameters
- $field : string
- $label : string
Return values
staticsetLabels()
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
staticsetLanguage()
public
setLanguage([Language|null $language = null ]) : static
Parameters
- $language : Language|null = null
Return values
staticsetMessage()
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
staticsetMessages()
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
staticsetRule()
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
staticsetRules()
Set field rules.
public
setRules(array<string, array<string|int, string>|string> $rules) : static
Parameters
- $rules : array<string, array<string|int, string>|string>
-
An associative array with field as keys and values as rules
Return values
staticvalidate()
Validate data with all rules.
public
validate(array<string, mixed> $data) : bool
Parameters
- $data : array<string, mixed>
Return values
boolvalidateOnly()
Validate only fields set on data.
public
validateOnly(array<string, mixed> $data) : bool
Parameters
- $data : array<string, mixed>
Return values
boolescapeArgs()
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<int, string>|string>>
Parameters
- $rules : string
Attributes
- #[Pure]
Return values
array<int, array<string, array<int, string>|string>>parseRule()
protected
parseRule(string $rule) : array<string, array<int, string>|string>
Parameters
- $rule : string
Return values
array<string, array<int, string>|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
boolsetEqualsField()
protected
setEqualsField(array<string, mixed> $rule) : array<string, mixed>
Parameters
- $rule : array<string, mixed>
Attributes
- #[Pure]
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
Return values
boolvalidateOnlySet()
protected
validateOnlySet(array<string, mixed> $data) : bool
Parameters
- $data : array<string, mixed>
Return values
boolvalidateRule()
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>