diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index 2188e896..3d2a4831 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -326,6 +326,11 @@ public function formatValue($value, ?string $modifier): string } } + // object-to-scalar procession + if ($value instanceof \BackedEnum && is_scalar($value->value)) { + $value = $value->value; + } + // with modifier procession if ($modifier) { if ($value !== null && !is_scalar($value)) { // array is already processed diff --git a/tests/dibi/Translator.enums.phpt b/tests/dibi/Translator.enums.phpt new file mode 100644 index 00000000..270a8f81 --- /dev/null +++ b/tests/dibi/Translator.enums.phpt @@ -0,0 +1,41 @@ +formatValue(EnumInt::One, null)); + +Assert::equal(match ($config['driver']) { + 'sqlsrv' => "N'one'", + default => "'one'", +}, $translator->formatValue(EnumString::One, null)); + +Assert::equal('**Unexpected PureEnum**', $translator->formatValue(PureEnum::One, null));