interface TranslatableValidatorInterface implements ValidatorInterface (View source)

A modifier to the standard validator interface that enables translatable requirements and errors.

Methods

string[]
getRequirementStrings()

Get the validator requirements in the form of an array keyed by it's respective error code.

bool
isValid(mixed $mixed, ArrayAccess $error = null)

Is this mixed value valid.

setRequirementString(int $code, string|Closure $message)

Set the requirement string to a mixed value.

setErrorString(int $code, string|Closure $message)

Set the error string to a string or to a closure.

Details

string[] getRequirementStrings()

Get the validator requirements in the form of an array keyed by it's respective error code.

Return Value

string[]

Examples

<code>[self::E_TOO_SHORT => 'Must be at least 10 characters']</code>

bool isValid(mixed $mixed, ArrayAccess $error = null)

Is this mixed value valid.

Parameters

mixed $mixed

Can be any value

ArrayAccess $error

Return Value

bool

Exceptions

InvalidArgumentException

invalid mixed value type passed

setRequirementString(int $code, string|Closure $message)

Set the requirement string to a mixed value.

Parameters

int $code

The error code

string|Closure $message

Either a plain string, or a closure that returns a string

Examples

<code>$message</code> should be like<br />
<code>function(TranslatableValidatorInterface $validator, int $code): string</code>

setErrorString(int $code, string|Closure $message)

Set the error string to a string or to a closure.

Parameters

int $code

The error code

string|Closure $message

Either a plain string, or a closure that returns a string

Examples

<code>$message</code> should be like<br />
<code>function(TranslatableValidatorInterface $validator, int $code, mixed $passed): string</code><br />
where <code>$passed</code> is whatever was passed to <code>ValidatorInterface::isValid</code>