Skip to content

Commit

Permalink
Add EnumCast docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WendellAdriel committed Sep 1, 2023
1 parent 43a54bd commit f70941a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f70941a

Please sign in to comment.