ValidationInterface
in
Expected behavior of a validator
Table of Contents
Methods
- check() : bool
- Check; runs the validation process, returning true or false determining whether or not validation was successful.
- getError() : string
- Returns the error for a specified $field (or empty string if not set).
- getErrors() : array<string, string>
- Returns the array of errors that were encountered during a run() call. The array should be in the following format:
- getRuleGroup() : array<int, string>
- Get rule group.
- getRules() : array<string|int, mixed>
- Returns all of the rules currently defined.
- getValidated() : array<string|int, mixed>
- Returns the actual validated data.
- hasError() : bool
- Checks to see if an error exists for the given field.
- hasRule() : bool
- Checks to see if the rule for key $field has been set or not.
- listErrors() : string
- Returns the rendered HTML of the errors as defined in $template.
- loadRuleGroup() : array<string|int, mixed>
- Loads custom rule groups (if set) into the current rules.
- reset() : ValidationInterface
- Resets the class to a blank slate. Should be called whenever you need to process more than one array.
- run() : bool
- Runs the validation process, returning true/false determining whether validation was successful or not.
- setError() : ValidationInterface
- Sets the error for a specific field. Used by custom validation methods.
- setRule() : $this
- Sets an individual rule and custom error messages for a single field.
- setRuleGroup() : void
- Set rule group.
- setRules() : ValidationInterface
- Stores the rules that should be used to validate the items.
- showError() : string
- Displays a single error in formatted HTML as defined in the $template view.
- withRequest() : ValidationInterface
- Takes a Request object and grabs the input data to use from its array values.
Methods
check()
Check; runs the validation process, returning true or false determining whether or not validation was successful.
public
check(array<string|int, mixed>|bool|float|int|object|string|null $value, array<string|int, mixed>|string $rules[, array<int, string> $errors = [] ][, string|null $dbGroup = null ]) : bool
Parameters
- $value : array<string|int, mixed>|bool|float|int|object|string|null
-
Value to validate.
- $rules : array<string|int, mixed>|string
- $errors : array<int, string> = []
- $dbGroup : string|null = null
-
The database group to use.
Return values
bool —True if valid, else false.
getError()
Returns the error for a specified $field (or empty string if not set).
public
getError(string $field) : string
Parameters
- $field : string
Return values
stringgetErrors()
Returns the array of errors that were encountered during a run() call. The array should be in the following format:
public
getErrors() : array<string, string>
[ 'field1' => 'error message', 'field2' => 'error message', ]
Return values
array<string, string>getRuleGroup()
Get rule group.
public
getRuleGroup(string $group) : array<int, string>
Parameters
- $group : string
-
Group.
Return values
array<int, string> —Rule group.
getRules()
Returns all of the rules currently defined.
public
getRules() : array<string|int, mixed>
Return values
array<string|int, mixed>getValidated()
Returns the actual validated data.
public
getValidated() : array<string|int, mixed>
Return values
array<string|int, mixed>hasError()
Checks to see if an error exists for the given field.
public
hasError(string $field) : bool
Parameters
- $field : string
Return values
boolhasRule()
Checks to see if the rule for key $field has been set or not.
public
hasRule(string $field) : bool
Parameters
- $field : string
Return values
boollistErrors()
Returns the rendered HTML of the errors as defined in $template.
public
listErrors([string $template = 'list' ]) : string
Parameters
- $template : string = 'list'
Return values
stringloadRuleGroup()
Loads custom rule groups (if set) into the current rules.
public
loadRuleGroup([non-empty-string|null $group = null ]) : array<string|int, mixed>
Rules can be pre-defined in Config\Validation and can be any name, but must all still be an array of the same format used with setRules(). Additionally, check for {group}_errors for an array of custom error messages.
Parameters
- $group : non-empty-string|null = null
Return values
array<string|int, mixed>reset()
Resets the class to a blank slate. Should be called whenever you need to process more than one array.
public
reset() : ValidationInterface
Return values
ValidationInterfacerun()
Runs the validation process, returning true/false determining whether validation was successful or not.
public
run([array<string|int, mixed>|null $data = null ][, string|null $group = null ][, array<string|int, mixed>|BaseConnection|non-empty-string|null $dbGroup = null ]) : bool
Parameters
- $data : array<string|int, mixed>|null = null
-
The array of data to validate.
- $group : string|null = null
-
The predefined group of rules to apply.
- $dbGroup : array<string|int, mixed>|BaseConnection|non-empty-string|null = null
-
The database group to use.
Return values
boolsetError()
Sets the error for a specific field. Used by custom validation methods.
public
setError(string $alias, string $error) : ValidationInterface
Parameters
- $alias : string
- $error : string
Return values
ValidationInterfacesetRule()
Sets an individual rule and custom error messages for a single field.
public
setRule(string $field, string|null $label, array<string|int, mixed>|string $rules[, array<string|int, mixed> $errors = [] ]) : $this
The custom error message should be just the messages that apply to this field, like so:
[ 'rule' => 'message', 'rule' => 'message', ]
Parameters
- $field : string
- $label : string|null
- $rules : array<string|int, mixed>|string
- $errors : array<string|int, mixed> = []
Return values
$thissetRuleGroup()
Set rule group.
public
setRuleGroup(string $group) : void
Parameters
- $group : string
-
Group.
setRules()
Stores the rules that should be used to validate the items.
public
setRules(array<string|int, mixed> $rules[, array<string|int, mixed> $messages = [] ]) : ValidationInterface
Parameters
- $rules : array<string|int, mixed>
- $messages : array<string|int, mixed> = []
Return values
ValidationInterfaceshowError()
Displays a single error in formatted HTML as defined in the $template view.
public
showError(string $field[, string $template = 'single' ]) : string
Parameters
- $field : string
- $template : string = 'single'
Return values
stringwithRequest()
Takes a Request object and grabs the input data to use from its array values.
public
withRequest(RequestInterface $request) : ValidationInterface
Parameters
- $request : RequestInterface