zero-to-prod/transformable

将类转换成不同类型。

v71.0.4 2024-09-04 10:53 UTC

This package is auto-updated.

Last update: 2024-09-04 10:54:05 UTC


README

Repo Latest Version on Packagist test Downloads

将类转换成不同类型。

安装

您可以通过Composer安装此包

composer require zerotoprod/transformable

方法

  • toArray(): array 将对象的属性转换为关联数组。
  • toJson(): string 将对象的属性转换为JSON字符串。

使用方法

要在您的类中使用Zerotoprod\Transformable\Transformable特性,只需包含它

use Zerotoprod\Transformable\Transformable;

class YourDataModel
{
    use Transformable;

    public $name;
    public $email;
}

$model = new YourDataModel();
$model->name = 'John Doe';
$model->email = 'john.doe@example.com';

$array = $model->toArray();
$json = $model->toJson();