class Enum implements Rule, Stringable, ValidatorAwareRule

Traits

Properties

protected Validator|null $validator

The current validator instance.

protected array $only

The cases that should be considered valid.

protected array $except

The cases that should be considered invalid.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

__construct(string $type)

Create a new rule instance.

bool
passes(string $attribute, mixed $value)

Determine if the validation rule passes.

only(mixed $values)

Specify the cases that should be considered valid.

except(mixed $values)

Specify the cases that should be considered invalid.

bool
isDesirable(mixed $value)

Determine if the given case is a valid case based on the only / except values.

array|string
message()

Get the validation error message.

setValidator(Validator $validator)

Set the current validator.

string
__toString()

Convert the rule to a validation string.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 43
__construct(string $type)

Create a new rule instance.

Parameters

string $type

the type of the enum

at line 51
bool passes(string $attribute, mixed $value)

Determine if the validation rule passes.

Parameters

string $attribute
mixed $value

Return Value

bool

at line 76
Enum only(mixed $values)

Specify the cases that should be considered valid.

Parameters

mixed $values

Return Value

Enum

at line 88
Enum except(mixed $values)

Specify the cases that should be considered invalid.

Parameters

mixed $values

Return Value

Enum

at line 98
protected bool isDesirable(mixed $value)

Determine if the given case is a valid case based on the only / except values.

Parameters

mixed $value

Return Value

bool

at line 110
array|string message()

Get the validation error message.

Return Value

array|string

at line 122
ValidatorAwareRule setValidator(Validator $validator)

Set the current validator.

Parameters

Validator $validator

Return Value

ValidatorAwareRule

at line 132
string __toString()

Convert the rule to a validation string.

Return Value

string