Skip to content

Commit d2d120f

Browse files
committed
fix(doctrine): support integer-backed enums in BackedEnumFilter
1 parent b1eeb98 commit d2d120f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Doctrine/Common/Filter/BackedEnumFilterTrait.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait BackedEnumFilterTrait
3232
use PropertyHelperTrait;
3333

3434
/**
35-
* @var array<string, string>
35+
* @var array<string, class-string>
3636
*/
3737
private array $enumTypes;
3838

@@ -80,6 +80,14 @@ abstract protected function isBackedEnumField(string $property, string $resource
8080

8181
private function normalizeValue($value, string $property): mixed
8282
{
83+
$firstCase = $this->enumTypes[$property]::cases()[0] ?? null;
84+
if (
85+
is_int($firstCase?->value)
86+
&& false !== filter_var($value, FILTER_VALIDATE_INT)
87+
) {
88+
$value = (int) $value;
89+
}
90+
8391
$values = array_map(fn (\BackedEnum $case) => $case->value, $this->enumTypes[$property]::cases());
8492

8593
if (\in_array($value, $values, true)) {

0 commit comments

Comments
 (0)