class Enum implements Rule, ValidatorAwareRule (View source)

Traits

Properties

protected string $type

The type of the enum.

protected Validator $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

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

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

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

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

void
__construct(string $type)

Create a new rule instance.

bool
passes(string $attribute, mixed $value)

Determine if the validation rule passes.

$this
only(UnitEnum[]|UnitEnum $values)

Specify the cases that should be considered valid.

$this
except(UnitEnum[]|UnitEnum $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.

string|array
message()

Get the validation error message.

$this
setValidator(Validator $validator)

Set the current validator.

Details

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

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

Parameters

$value
callable $callback
callable $default

Return Value

$this|TWhenReturnType

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

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

Parameters

$value
callable $callback
callable $default

Return Value

$this|TUnlessReturnType

void __construct(string $type)

Create a new rule instance.

Parameters

string $type

Return Value

void

bool passes(string $attribute, mixed $value)

Determine if the validation rule passes.

Parameters

string $attribute
mixed $value

Return Value

bool

$this only(UnitEnum[]|UnitEnum $values)

Specify the cases that should be considered valid.

Parameters

UnitEnum[]|UnitEnum $values

Return Value

$this

$this except(UnitEnum[]|UnitEnum $values)

Specify the cases that should be considered invalid.

Parameters

UnitEnum[]|UnitEnum $values

Return Value

$this

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

string|array message()

Get the validation error message.

Return Value

string|array

$this setValidator(Validator $validator)

Set the current validator.

Parameters

Validator $validator

Return Value

$this