muffe / enum-constraint
A Symfony Validator constraint that validates if given strings are valid cases in a given PHP 8 Enum
Installs: 5 916
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- symfony/validator: ^5.0|^6.0|^7.0
README
A Symfony Validator constraint that validates if given strings are valid cases in a given PHP 8 Enum
enum ContactCategory: string
{
case Child = 'Child';
case Grandchild = 'Grandchild';
}
use Muffe\EnumConstraint\Constraints\Enum;
#[
Enum(
enumType: ContactCategory::class,
)
]
public ?string $category = null;
Validates that $category contains a string that is equal to the backed value of one of the given enum cases, or the name of the case if no backed values are given.
use Muffe\EnumConstraint\Constraints\Enum;
#[
Enum(
enumType: ContactCategory::class,
multiple: true
)
]
public ?array $categories = null;
Also supports validating multiple given values