From dab5fc60370f77a3ed463dc75897d26cfd7f7e96 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 9 Sep 2024 11:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E4=BC=98?= =?UTF-8?q?=E5=85=88=E5=88=A4=E6=96=ADFieldTypeTransform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/concern/Attribute.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/model/concern/Attribute.php b/src/model/concern/Attribute.php index b0edd2a7..f381f398 100644 --- a/src/model/concern/Attribute.php +++ b/src/model/concern/Attribute.php @@ -470,10 +470,10 @@ protected function writeTransform($value, string | array $type) $typeTransform = static function (string $type, $value, $model) { if (str_contains($type, '\\') && class_exists($type)) { - if ($value instanceof BackedEnum) { - $value = $value->value; - } elseif (is_subclass_of($type, FieldTypeTransform::class)) { + if (is_subclass_of($type, FieldTypeTransform::class)) { $value = $type::set($value, $model); + } elseif ($value instanceof BackedEnum) { + $value = $value->value; } elseif ($value instanceof Stringable) { $value = $value->__toString(); } @@ -645,13 +645,13 @@ protected function readTransform($value, string | array $type) $typeTransform = static function (string $type, $value, $model) { if (str_contains($type, '\\') && class_exists($type)) { - if (is_subclass_of($type, BackedEnum::class)) { + if (is_subclass_of($type, FieldTypeTransform::class)) { + $value = $type::get($value, $model); + } elseif (is_subclass_of($type, BackedEnum::class)) { $value = $type::from($value); if (is_subclass_of($type, EnumTransform::class)) { $value = $value->value(); } - } elseif (is_subclass_of($type, FieldTypeTransform::class)) { - $value = $type::get($value, $model); } else { // 对象类型 $value = new $type($value);