class Unique extends Rule implements RuleInterface

Unique rule.

Traits

I18n aware trait.
Doesn't validate when empty trait.

Properties

protected I18n $i18n I18n. from I18nAwareTrait
protected string $table Table.
protected string $column Column.
protected mixed $allowed Allowed value.
protected string|null $connection Connection.
protected ConnectionManager $database Connection manager.
protected array $i18nParameters I18n parameters.

Methods

setI18n(I18n $i18n)

Sets the I18n instance.

string
translateFieldName(string $field, string $package)

Returns a translated field name.

array
getI18nParameters(string $field, string $package)

Gets the i18n parameters.

string
getTranslatedErrorMessage(string $field, string $rule, string|null $package = null)

Returns the translated error message.

bool
validateWhenEmpty()

Returns TRUE if the rule should be executed when the input is empty and FALSE if not.

__construct(string $table, string $column, mixed $allowed = null, string|null $connection, ConnectionManager $database)

Constructor.

bool
validate(mixed $value, array $input)

Returns TRUE if the rule succeeds and FALSE if not.

string
getErrorMessage(string $field)

Returns an error message.

Details

in I18nAwareTrait at line 44
RuleInterface setI18n(I18n $i18n)

Sets the I18n instance.

Parameters

I18n $i18n I18n

Return Value

RuleInterface

in I18nAwareTrait at line 58
protected string translateFieldName(string $field, string $package)

Returns a translated field name.

Parameters

string $field Field name
string $package Package prefix

Return Value

string

in I18nAwareTrait at line 79
protected array getI18nParameters(string $field, string $package)

Gets the i18n parameters.

Parameters

string $field Field name
string $package Package prefix

Return Value

array

in I18nAwareTrait at line 110
string getTranslatedErrorMessage(string $field, string $rule, string|null $package = null)

Returns the translated error message.

Parameters

string $field Field name
string $rule Rule name
string|null $package Package name

Return Value

string

bool validateWhenEmpty()

Returns TRUE if the rule should be executed when the input is empty and FALSE if not.

Return Value

bool

at line 74
__construct(string $table, string $column, mixed $allowed = null, string|null $connection, ConnectionManager $database)

Constructor.

Parameters

string $table Table
string $column Column
mixed $allowed Allowed value
string|null $connection Connection
ConnectionManager $database Connection manager

at line 90
bool validate(mixed $value, array $input)

Returns TRUE if the rule succeeds and FALSE if not.

Parameters

mixed $value Value to validate
array $input Input

Return Value

bool

at line 112
string getErrorMessage(string $field)

Returns an error message.

Parameters

string $field Field name

Return Value

string