PHP Validation

AbstractValidation extends AbstractRule
in package
implements ValidationInterface

AbstractYes

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

Properties

$errors

private array<string, array<string, mixed>> $errors = []

$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
int

getErrorMessage()

Retrieve last error message.

public getErrorMessage() : string
Return values
string

getErrors()

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|null

getMethods()

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
bool

hasMethod()

Checks if a method exists by the given case-sensitive name.

public hasMethod(string $Name) : bool
Parameters
$Name : string

The method name.

Return values
bool

hasRule()

Checks if a rule exists by the given case-sensitive name.

public hasRule(string $Name) : bool
Parameters
$Name : string

The rule name.

Return values
bool

isValid()

Check if data is valid.

public isValid(array<string, mixed> $Data) : bool
Parameters
$Data : array<string, mixed>

The data to be validated.

Tags
throws
InvalidArgumentException

If error.

Return values
bool

validate()

Validate the data using defined rules.

public validate(array<string, mixed> $Data) : static
Parameters
$Data : array<string, mixed>

The data to be validated.

Tags
throws
InvalidArgumentException

If error.

throws
ValidationException

If invalid.

Return values
static

withError()

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
static

withMethod()

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
static

withoutError()

Return an instance without the specified error.

public withoutError(string $Name) : static
Parameters
$Name : string

The error name.

Return values
static

withoutMethod()

Return an instance without the specified method.

public withoutMethod(string $Name) : static
Parameters
$Name : string

The method name.

Return values
static

withoutRule()

Return an instance without the specified rule.

public withoutRule(string $Name) : static
Parameters
$Name : string

The rule name.

Return values
static

withRule()

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
static

interpolate()

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
string

executeAssertationCallback()

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
throws
InvalidArgumentException

If error.

Return values
bool

getAssertationCallback()

Retrieve assertation callback.

private getAssertationCallback(string $Assert) : callable
Parameters
$Assert : string

The assert name.

Tags
throws
InvalidArgumentException

If error.

Return values
callable

verifyMandatoryRule()

Verify mandatory rule.

private verifyMandatoryRule(array<string, mixed> $Data) : bool
Parameters
$Data : array<string, mixed>

The data to be validated.

Tags
throws
InvalidArgumentException

If error.

Return values
bool

verifyOptionalRule()

Verify optional rule.

private verifyOptionalRule(array<string, mixed> $Data) : bool
Parameters
$Data : array<string, mixed>

The data to be validated.

Tags
throws
InvalidArgumentException

If error.

Return values
bool

        
On this page

Search results