-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# enum-constraint | ||
A Symfony Validator constraint that validates of given strings a 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 |