Skip to content

Commit 3af8cd1

Browse files
committed
fix(mapper): handle non-backed enums in EnumCaster
1 parent 65a1c01 commit 3af8cd1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/mapper/src/Casters/EnumCaster.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Tempest\Mapper\Casters;
66

77
use Tempest\Mapper\Caster;
8+
use Tempest\Mapper\Exceptions\ValueCouldNotBeCast;
89
use UnitEnum;
910

1011
final readonly class EnumCaster implements Caster
@@ -22,6 +23,10 @@ public function cast(mixed $input): ?object
2223
return null;
2324
}
2425

26+
if (!is_a($this->enum, \BackedEnum::class, allow_string: true)) {
27+
return null;
28+
}
29+
2530
if (is_a($input, $this->enum)) {
2631
return $input;
2732
}

0 commit comments

Comments
 (0)