Skip to content

Commit

Permalink
尝试调整接口命名
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX authored and liu21st committed Aug 16, 2024
1 parent 4d7db18 commit ca1f2ef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ protected function writeTransform($value, string|array $type)
$typeTransform = static function (string $type, $value, $model) {
if (str_contains($type, '\\') && class_exists($type)) {
if (is_subclass_of($type, FieldTypeTransform::class)) {
$value = $type::modelWriteValue($value, $model);
$value = $type::set($value, $model);
} elseif ($value instanceof Stringable) {
$value = $value->__toString();
}
Expand Down Expand Up @@ -641,7 +641,7 @@ 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, FieldTypeTransform::class)) {
$value = $type::modelReadValue($value, $model);
$value = $type::get($value, $model);
} else {
// 对象类型
$value = new $type($value);
Expand Down
4 changes: 2 additions & 2 deletions src/model/contracts/FieldTypeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

interface FieldTypeTransform
{
public static function modelReadValue(mixed $value, Model $model): static;
public static function get(mixed $value, Model $model): static;

/**
* @return static|mixed
*/
public static function modelWriteValue($value, Model $model): mixed;
public static function set($value, Model $model): mixed;
}
4 changes: 2 additions & 2 deletions tests/stubs/TestFieldJsonDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function __toString(): string
return json_encode($this);
}

public static function modelReadValue(mixed $value, Model $model): static
public static function get(mixed $value, Model $model): static
{
return static::fromData($value);
}

public static function modelWriteValue($value, $model): string
public static function set($value, $model): string
{
return (string) $value;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/stubs/TestFieldPhpDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function __toString(): string
return serialize($this);
}

public static function modelReadValue(mixed $value, Model $model): static
public static function get(mixed $value, Model $model): static
{
$d = static::fromData($value);
$d->id = $model->getData('id');
return $d;
}

public static function modelWriteValue($value, $model): string
public static function set($value, $model): string
{
return (string) $value;
}
Expand Down

0 comments on commit ca1f2ef

Please sign in to comment.