diff --git a/src/Form/UiSelect.php b/src/Form/UiSelect.php index 168c60f..3a38548 100644 --- a/src/Form/UiSelect.php +++ b/src/Form/UiSelect.php @@ -79,13 +79,23 @@ class UiSelect extends UiElement implements Extension { return $option; } - protected function isSelected($check, $value, bool $strict = true) : bool + protected function isSelected($check, mixed $value, bool $strict = true) : bool { if ( is_array($value) ) { - return in_array($check, $value, $strict); + return in_array($check, array_map(fn($e) => $this->normalizeValue($e), $value), $strict); } + $value = $this->normalizeValue($value); return $strict ? $check === $value : $check == $value; } + + protected function normalizeValue(mixed $value) : mixed + { + if ($value instanceof \BackedEnum) { + return $value->value; + } + + return $value; + } } diff --git a/src/Method/FormContext.php b/src/Method/FormContext.php index c9364e3..37ca126 100644 --- a/src/Method/FormContext.php +++ b/src/Method/FormContext.php @@ -218,7 +218,7 @@ class FormContext implements FormContextInterface is_null($value) => null, enum_exists($e) => ( $value instanceof \BackedEnum ? $value : $e::tryFrom($value) ) ?? throw new \InvalidArgumentException(sprintf("Field '\$$property' awaiting values : '%s'.", implode("', '", array_map(fn($e) => $e->value, $e::cases())))), function_exists($e) => $e($value), - class_exists($e) => new $e($value), + class_exists($e) => new $e(...$value), interface_exists($e) => throw new \InvalidArgumentException("There is no way provided to match an interface object yet."), default => $value };