承接 soyhuce/data-transfer-object-casts 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

soyhuce/data-transfer-object-casts

最新稳定版本:0.1.1

Composer 安装命令:

composer require soyhuce/data-transfer-object-casts

包简介

Common casts for spatie/data-transfer-object

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status GitHub PHPStan Action Status Total Downloads

Common casts for spatie/data-transfer-object

Installation

You can install the package via composer:

composer require soyhuce/data-transfer-object-casts

Usage

BooleanCaster

Casts the input into boolean, if applicable.

use Soyhuce\DataTransferObjectCasts\BooleanCaster;
use Spatie\DataTransferObject\Attributes\DefaultCast;
use Spatie\DataTransferObject\DataTransferObject;

#[DefaultCast('bool', BooleanCaster::class)]
class MyDTO extends DataTransferObject
{
    public bool $bool;
}

$dto = new MyDTO(
    bool: 'true',
);

$dto->bool; // true

CarbonImmutableCaster

Cast the input into a CarbonImmutable instance. If the input is not a string, it will be returned as is.

By default, the format is '!Y-m-d H:i:s'.

use Carbon\CarbonImmutable;
use Soyhuce\DataTransferObjectCasts\CarbonImmutableCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Attributes\DefaultCast;
use Spatie\DataTransferObject\DataTransferObject;

#[DefaultCast(CarbonImmutable::class, CarbonImmutableCaster::class)]
class MyDTO extends DataTransferObject
{
    public CarbonImmutable $dateTime;

    #[CastWith(CarbonImmutableCaster::class, '!Y-m-d')]
    public CarbonImmutable $date;
}

$dto = new MyDTO(
    dateTime: '2022-08-11 14:44:45',
    date: '2022-08-01',
);

$dto->dateTime; // CarbonImmutable instance
$dto->date; // CarbonImmutable instance

StringEnumCaster

Cast the input into a backed string enum.

use Soyhuce\DataTransferObjectCasts\StringEnumCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\DataTransferObject;

#[CastWith(StringEnumCaster::class)]
enum StringEnum: string
{
    case ok = 'ok';
    case nok = 'nok';
}

class MyDTO extends DataTransferObject
{
    public StringEnum $stringEnum;
}

$dto = new MyDTO(
    stringEnum: 'ok',
);

$dto->stringEnum; // StringEnum::ok

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固