定制 bluestone/dto 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bluestone/dto

最新稳定版本:v1.1.1

Composer 安装命令:

composer require bluestone/dto

包简介

Data transfer objects

README 文档

README

Run tests Latest Stable Version

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

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-21