Skip to content

Commit

Permalink
类型转换优先判断FieldTypeTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 9, 2024
1 parent 804bd69 commit dab5fc6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dab5fc6

Please sign in to comment.