AbstractValidation
extends AbstractRule
in package
implements
ValidationInterface
This is a simple Validation implementation that other Validation can inherit from.
Table of Contents
Interfaces
- ValidationInterface
- Describes Validation interface.
Constants
- ASSERT_MANDATORY = "required"
Properties
- $error_code : int
- $error_message : string
- $errors : array<string, array<string, mixed>>
- $methods : array<string, callable>
- $rules : array<string, array<string, mixed>>
Methods
- getError() : array<string, mixed>
- Retrieve a validation error value by the given case-sensitive name.
- getErrorCode() : int
- Retrieve last error code.
- getErrorMessage() : string
- Retrieve last error message.
- getErrors() : array<string, array<string, mixed>>
- Retrieves all validation error values.
- getMethod() : callable|null
- Retrieve a validation method callback by the given case-sensitive name.
- getMethods() : array<string, callable>
- Retrieves all validation method callbacks.
- getRule() : array<string, mixed>
- Retrieve a validation rule value by the given case-sensitive name.
- getRules() : array<string, array<string, mixed>>
- Retrieves all validation rule values.
- hasError() : bool
- Checks if a error exists by the given case-sensitive name.
- hasMethod() : bool
- Checks if a method exists by the given case-sensitive name.
- hasRule() : bool
- Checks if a rule exists by the given case-sensitive name.
- isValid() : bool
- Check if data is valid.
- validate() : static
- Validate the data using defined rules.
- withError() : static
- Return an instance with the provided value replacing the specified error.
- withMethod() : static
- Return an instance with the provided callback replacing the specified method.
- withoutError() : static
- Return an instance without the specified error.
- withoutMethod() : static
- Return an instance without the specified method.
- withoutRule() : static
- Return an instance without the specified rule.
- withRule() : static
- Return an instance with the provided value replacing the specified rule.
- interpolate() : string
- Interpolates context values into the message placeholders.
- executeAssertationCallback() : bool
- Execute assertation callback.
- getAssertationCallback() : callable
- Retrieve assertation callback.
- verifyMandatoryRule() : bool
- Verify mandatory rule.
- verifyOptionalRule() : bool
- Verify optional rule.
Constants
ASSERT_MANDATORY
private
mixed
ASSERT_MANDATORY
= "required"
Properties
$error_code
private
int
$error_code
= 0
$error_message
private
string
$error_message
= ""
$errors
private
array<string, array<string, mixed>>
$errors
= []
$methods
private
array<string, callable>
$methods
= []
$rules
private
array<string, array<string, mixed>>
$rules
= []
Methods
getError()
Retrieve a validation error value by the given case-sensitive name.
public
getError(string $Name) : array<string, mixed>
Parameters
- $Name : string
-
The error name.
Return values
array<string, mixed>getErrorCode()
Retrieve last error code.
public
getErrorCode() : int
Return values
intgetErrorMessage()
Retrieve last error message.
public
getErrorMessage() : string
Return values
stringgetErrors()
Retrieves all validation error values.
public
getErrors() : array<string, array<string, mixed>>
Return values
array<string, array<string, mixed>>getMethod()
Retrieve a validation method callback by the given case-sensitive name.
public
getMethod(string $Name) : callable|null
Parameters
- $Name : string
-
The method name.
Return values
callable|nullgetMethods()
Retrieves all validation method callbacks.
public
getMethods() : array<string, callable>
Return values
array<string, callable>getRule()
Retrieve a validation rule value by the given case-sensitive name.
public
getRule(string $Name) : array<string, mixed>
Parameters
- $Name : string
-
The rule name.
Return values
array<string, mixed>getRules()
Retrieves all validation rule values.
public
getRules() : array<string, array<string, mixed>>
Return values
array<string, array<string, mixed>>hasError()
Checks if a error exists by the given case-sensitive name.
public
hasError(string $Name) : bool
Parameters
- $Name : string
-
The error name.
Return values
boolhasMethod()
Checks if a method exists by the given case-sensitive name.
public
hasMethod(string $Name) : bool
Parameters
- $Name : string
-
The method name.
Return values
boolhasRule()
Checks if a rule exists by the given case-sensitive name.
public
hasRule(string $Name) : bool
Parameters
- $Name : string
-
The rule name.
Return values
boolisValid()
Check if data is valid.
public
isValid(array<string, mixed> $Data) : bool
Parameters
- $Data : array<string, mixed>
-
The data to be validated.
Tags
Return values
boolvalidate()
Validate the data using defined rules.
public
validate(array<string, mixed> $Data) : static
Parameters
- $Data : array<string, mixed>
-
The data to be validated.
Tags
Return values
staticwithError()
Return an instance with the provided value replacing the specified error.
public
withError(string $Name, string $Message[, int $Code = 0 ]) : static
Parameters
- $Name : string
-
The error name.
- $Message : string
-
The error message.
- $Code : int = 0
-
The error code.
Return values
staticwithMethod()
Return an instance with the provided callback replacing the specified method.
public
withMethod(string $Name, callable $Callback) : static
Parameters
- $Name : string
-
The method name.
- $Callback : callable
-
The method callback.
Return values
staticwithoutError()
Return an instance without the specified error.
public
withoutError(string $Name) : static
Parameters
- $Name : string
-
The error name.
Return values
staticwithoutMethod()
Return an instance without the specified method.
public
withoutMethod(string $Name) : static
Parameters
- $Name : string
-
The method name.
Return values
staticwithoutRule()
Return an instance without the specified rule.
public
withoutRule(string $Name) : static
Parameters
- $Name : string
-
The rule name.
Return values
staticwithRule()
Return an instance with the provided value replacing the specified rule.
public
withRule(string $Name, array<string, mixed> $Rule) : static
Parameters
- $Name : string
-
The rule name.
- $Rule : array<string, mixed>
-
The rule value.
Return values
staticinterpolate()
Interpolates context values into the message placeholders.
protected
interpolate(string $message[, array<string, mixed> $context = array() ]) : string
Parameters
- $message : string
- $context : array<string, mixed> = array()
Return values
stringexecuteAssertationCallback()
Execute assertation callback.
private
executeAssertationCallback(callable $Method, string $Attribute, string $Assert, mixed $Expect, mixed $Actual, array<string, mixed> $Data) : bool
Parameters
- $Method : callable
-
The assertation method.
- $Attribute : string
-
The attribute name.
- $Assert : string
-
The assert name.
- $Expect : mixed
-
The expect value.
- $Actual : mixed
-
The actual value.
- $Data : array<string, mixed>
-
The data to be validated.
Tags
Return values
boolgetAssertationCallback()
Retrieve assertation callback.
private
getAssertationCallback(string $Assert) : callable
Parameters
- $Assert : string
-
The assert name.
Tags
Return values
callableverifyMandatoryRule()
Verify mandatory rule.
private
verifyMandatoryRule(array<string, mixed> $Data) : bool
Parameters
- $Data : array<string, mixed>
-
The data to be validated.
Tags
Return values
boolverifyOptionalRule()
Verify optional rule.
private
verifyOptionalRule(array<string, mixed> $Data) : bool
Parameters
- $Data : array<string, mixed>
-
The data to be validated.