akbsit / trait-dto
特质(Trait)有助于创建 DTO 对象。
1.0.3
2023-09-16 18:03 UTC
Requires
- php: ^8.1
- akbsit/trait-singleton: ^1.0
- dusank/knapsack: ^10.0
This package is auto-updated.
Last update: 2024-09-16 20:59:52 UTC
README
安装
要安装包,你需要运行以下命令
composer require akbsit/trait-dto
示例
使用特质 DtoTrait
创建 DTO 类
<?php namespace App\Classes; use Akbsit\TraitDto\DtoTrait; /** * Class ExampleDto * @package App\Classes */ class ExampleDto { use DtoTrait; /* @var int */ public $iIntProperty; /* @var string */ public $sStringProperty; /* @var array */ public $arArrayProperty; }
创建对象
$oExampleDto = ExampleDto::instance()->create([ 'iIntProperty' => 10, 'sStringProperty' => 'string', 'arArrayProperty' => [ 'key1' => 'value1', 'key2' => 'value2', ], ]);
object(App\Classes\ExampleDto)#208 (3) {
["iIntProperty"]=>
int(10)
["sStringProperty"]=>
string(6) "string"
["arArrayProperty"]=>
array(2) {
["key1"]=>
string(6) "value1"
["key2"]=>
string(6) "value2"
}
}