Skip to content

Commit

Permalink
类型转换改进类型识别
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 28, 2025
1 parent c13415c commit 04ad06e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ protected function readTransform($value, string | array $type)

return match ($type) {
'string' => (string) $value,
'int' => (int) $value,
'int','integer' => (int) $value,
'float' => empty($param) ? (float) $value : (float) number_format($value, (int) $param, '.', ''),
'bool' => (bool) $value,
'bool','boolean' => (bool) $value,
'array' => empty($value) ? [] : (is_array($value) ? $value : json_decode($value, true)),
'object' => empty($value) ? new \stdClass() : (is_string($value) ? json_decode($value) : json_decode(json_encode($value, JSON_FORCE_OBJECT))),
'json' => $typeTransform(Json::class, $value, $this),
Expand Down Expand Up @@ -298,9 +298,9 @@ protected function writeTransform($value, string | array $type)

return match ($type) {
'string' => (string) $value,
'int' => (int) $value,
'int','integer' => (int) $value,
'float' => empty($param) ? (float) $value : (float) number_format($value, (int) $param, '.', ''),
'bool' => (bool) $value,
'bool','boolean' => (bool) $value,
'object' => is_object($value) ? json_encode($value, JSON_FORCE_OBJECT) : $value,
'array' => json_encode((array) $value, JSON_UNESCAPED_UNICODE),
'json' => $typeTransform(Json::class, $value, $this),
Expand Down

0 comments on commit 04ad06e

Please # to comment.