ValidationInterface
in
Expected behavior of a validator
Table of Contents
- 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:
- hasRule() : bool
- Checks to see if the rule for key $field has been set or not.
- 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 or not validation was successful.
- setError() : ValidationInterface
- Sets the error for a specific field. Used by custom validation methods.
- setRules() : ValidationInterface
- Stores the rules that should be used to validate the items.
- 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(mixed $value, string $rule[, array<string|int, string> $errors = [] ]) : bool
Parameters
- $value : mixed
-
Value to validation.
- $rule : string
-
Rule.
- $errors : array<string|int, string> = []
-
Errors.
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
string —getErrors()
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> —hasRule()
Checks to see if the rule for key $field has been set or not.
public
hasRule(string $field) : bool
Parameters
- $field : string
Return values
bool —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
ValidationInterface —run()
Runs the validation process, returning true/false determining whether or not validation was successful.
public
run([array<string|int, mixed> $data = null ][, string $group = null ]) : bool
Parameters
- $data : array<string|int, mixed> = null
-
The array of data to validate.
- $group : string = null
-
The pre-defined group of rules to apply.
Return values
bool —setError()
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
ValidationInterface —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
ValidationInterface —withRequest()
Takes a Request object and grabs the input data to use from its array values.
public
withRequest(RequestInterface $request) : ValidationInterface
Parameters
- $request : RequestInterface