muffe/enum-constraint

A Symfony Validator constraint that validates if given strings are valid cases in a given PHP 8 Enum

Installs: 9 680

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

pkg:composer/muffe/enum-constraint

v0.2.1 2025-03-22 19:56 UTC

This package is auto-updated.

Last update: 2025-10-22 21:21:39 UTC


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