IsInSet
extends Base
in package
Validates that a value is within a predefined set of allowed values.
This validator is commonly used for enum-like validations where a value must be one of a specific set of allowed options. It supports both strict and loose comparison modes.
Tags
Table of Contents
Properties
- $_allowedValues : array<string|int, mixed>
- $_strict : bool
Methods
- __construct() : mixed
- getAllowedValues() : array<string|int, mixed>
- Get the array of allowed values.
- isStrict() : bool
- Check if strict comparison is enabled.
- isValid() : bool
- Returns true if validation is successful
- setAllowedValues() : void
- Set the array of allowed values.
- setStrict() : void
- Set whether to use strict comparison.
- validate() : bool
- Validates that the value is in the allowed set.
Properties
$_allowedValues
private
array<string|int, mixed>
$_allowedValues
$_strict
private
bool
$_strict
Methods
__construct()
public
__construct(array<string|int, mixed> $allowedValues[, bool $strict = true ]) : mixed
Parameters
- $allowedValues : array<string|int, mixed>
-
Array of allowed values
- $strict : bool = true
-
Whether to use strict comparison (default: true)
getAllowedValues()
Get the array of allowed values.
public
getAllowedValues() : array<string|int, mixed>
Return values
array<string|int, mixed>isStrict()
Check if strict comparison is enabled.
public
isStrict() : bool
Return values
boolisValid()
Returns true if validation is successful
public
isValid(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolsetAllowedValues()
Set the array of allowed values.
public
setAllowedValues(array<string|int, mixed> $allowedValues) : void
Parameters
- $allowedValues : array<string|int, mixed>
setStrict()
Set whether to use strict comparison.
public
setStrict(bool $strict) : void
Parameters
- $strict : bool
validate()
Validates that the value is in the allowed set.
protected
validate(mixed $value) : bool
Parameters
- $value : mixed