abstract class Rule implements RuleInterface

Base class for all form validation rules

Constants

INTEGER_TYPE

STRING_TYPE

FLOAT_TYPE

BOOLEAN_TYPE

NUMBER_TYPE

ITEMS_ARRAY

Properties

protected string|null $error Rule error
protected string|null $defaultError Default errror code
protected array $errorParams Error params
protected Collection $params Rule params

Methods

mixed
getType()

Return rule type

bool
validate(mixed $value)

Validate rule value callback

__construct(array $params = [], string|null $error = null)

Constructor

void
setDefaultError(string $errorCode)

Set default error code

Collection
getParams()

Return rule params

boolean
isRequired()

Return true if field rule is required

void
required(boolean $value = true)

Set rule required

bool
validateType(mixed $value, int $type)

Validate field type

void
setError(string|null $error, string|null $default = null)

Set validation error ode

array
getErrorParams()

Get error params

void
setErrorParams(array $params = [])

Set error params

string|null
getError()

Return validation error code

Details

at line 60
abstract mixed getType()

Return rule type

Return Value

mixed

at line 68
bool validate(mixed $value)

Validate rule value callback

Parameters

mixed $value

Return Value

bool

at line 79
__construct(array $params = [], string|null $error = null)

Constructor

Parameters

array $params
string|null $error

at line 92
void setDefaultError(string $errorCode)

Set default error code

Parameters

string $errorCode

Return Value

void

at line 102
Collection getParams()

Return rule params

Return Value

Collection

at line 112
boolean isRequired()

Return true if field rule is required

Return Value

boolean

at line 123
void required(boolean $value = true)

Set rule required

Parameters

boolean $value

Return Value

void

at line 135
protected bool validateType(mixed $value, int $type)

Validate field type

Parameters

mixed $value
int $type

Return Value

bool

at line 174
void setError(string|null $error, string|null $default = null)

Set validation error ode

Parameters

string|null $error
string|null $default

Return Value

void

at line 185
array getErrorParams()

Get error params

Return Value

array

at line 196
void setErrorParams(array $params = [])

Set error params

Parameters

array $params

Return Value

void

at line 206
string|null getError()

Return validation error code

Return Value

string|null