From f70941a824b78b5fc76b7f4ef7ddd9c3a99964ae Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Fri, 1 Sep 2023 20:28:48 +0100 Subject: [PATCH] Add EnumCast docs --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 85dcbc9..bad84ef 100644 --- a/README.md +++ b/README.md @@ -775,6 +775,24 @@ protected function casts(): array } ``` +### Enum + +This will try to convert the value to the given `Enum` class. It works with `UnitEnum` and `BackedEnum`. + +This will throw a `WendellAdriel\ValidatedDTO\Exceptions\CastException` exception if the property is not a valid enum value. + +This will throw a `WendellAdriel\ValidatedDTO\Exceptions\CastTargetException` exception if the class passed to the +`EnumCast` constructor is not a `Enum` instance. + +```php +protected function casts(): array +{ + return [ + 'property' => new EnumCast(MyEnum::class), + ]; +} +``` + ### Float If a not numeric value is found, it will throw a `WendellAdriel\ValidatedDTO\Exceptions\CastException` exception.