bluestone/dto
最新稳定版本:v1.1.1
Composer 安装命令:
composer require bluestone/dto
包简介
Data transfer objects
README 文档
README
Installation
This package requires php:^8.1.
You can install it via composer:
composer require bluestone/dto
Usage
This package goal to simplify the build of objects whose serve to pass structured data.
Build simple DTO
An exemple of class extends DTO :
use Bluestone\DataTransferObject\DataTransferObject; class Hooman extends DataTransferObject { public string $name; }
You can instantiate this class like this :
$jane = new Hooman(name: 'Jane'); $john = new Hooman(['name' => 'John']);
Build complex DTO with Casting
An exemple of class with property with casting :
use Bluestone\DataTransferObject\DataTransferObject; use Bluestone\DataTransferObject\Attributes\CastWith; use Bluestone\DataTransferObject\Casters\ArrayCaster; class Hooman extends DataTransferObject { public string $name; #[CastWith(ArrayCaster::class, type: Hooman::class)] public array $children; }
You can instantiate this class like this :
$jane = new Hooman( name: 'Jane', children: [ new Hooman(name: 'Mario'), new Hooman(name: 'Luigi'), ], ); $john = new Hooman([ 'name' => 'John', 'children' => [ ['name' => 'Mario'], ['name' => 'Luigi'], ], ]);
Build complex DTO with Mapping
An exemple of class with property with mapping :
use Bluestone\DataTransferObject\DataTransferObject; use Bluestone\DataTransferObject\Attributes\Map; class Hooman extends DataTransferObject { #[Map('date_of_birth')] public string $bornAt; }
You can instantiate this class like this :
$jane = new Hooman( date_of_birth: '1970-01-01', ); $john = new Hooman([ 'date_of_birth' => '1970-01-01', ]);
Contributing
DTO is an open source project under MIT License and is open for contributions.
统计信息
- 总下载量: 1.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-21