From fc0fef1a43ed93e6e1f088f91503ab48c01832c2 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Mon, 8 Jun 2026 15:30:54 +0800 Subject: [PATCH 1/2] feat: support enum value resolution in data object --- src/support/src/DataObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/support/src/DataObject.php b/src/support/src/DataObject.php index a018423e0..63a9a48dc 100644 --- a/src/support/src/DataObject.php +++ b/src/support/src/DataObject.php @@ -291,7 +291,7 @@ protected static function resolveDependenciesMap(string $class, array &$visited : $property->getName(); if (enum_exists($typeName)) { $result[$dataKey] = [ - 'handler' => [$typeName, 'from'], + 'handler' => fn ($value) => $value instanceof $typeName ? $value : $typeName::from($value), 'nullable' => $allowsNull, 'children' => [], ]; From 4380306e745d033c3e0159824cdfac4e5bbb7b2b Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Mon, 8 Jun 2026 15:40:38 +0800 Subject: [PATCH 2/2] improve: only auto-convert backed enums in data object --- src/support/src/DataObject.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/support/src/DataObject.php b/src/support/src/DataObject.php index 63a9a48dc..03f6df995 100644 --- a/src/support/src/DataObject.php +++ b/src/support/src/DataObject.php @@ -5,6 +5,7 @@ namespace Hypervel\Support; use ArrayAccess; +use BackedEnum; use Carbon\Carbon as BaseCarbon; use Carbon\CarbonInterface; use DateTime; @@ -289,7 +290,7 @@ protected static function resolveDependenciesMap(string $class, array &$visited $dataKey = static::isAutoCasting() ? static::convertPropertyToDataKey($property->getName()) : $property->getName(); - if (enum_exists($typeName)) { + if (enum_exists($typeName) && is_subclass_of($typeName, BackedEnum::class, true)) { $result[$dataKey] = [ 'handler' => fn ($value) => $value instanceof $typeName ? $value : $typeName::from($value), 'nullable' => $allowsNull,