承接 morningtrain/data-transfer-object-casters 相关项目开发

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

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

morningtrain/data-transfer-object-casters

最新稳定版本:2.0.0

Composer 安装命令:

composer require morningtrain/data-transfer-object-casters

包简介

A package containing Data Transfer Object casters, for use with spatie/data-transfer-object

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Code style Total Downloads

Installation

You can install the package via composer:

composer require morningtrain/data-transfer-object-casters

Usage

To use the provided casters, add an attribute CastWith, to the property you want to cast.

class DTO extends DataTransferObject
{
    #[CastWith(BoolCaster::class)]
    public bool $bool;
}

Bool

The Boolean caster is used to cast the provided value to a boolean.

It uses FILTER_VALIDATE_BOOL, see the php docs for more information

Date

The DateCaster will attempt to cast the provided value into a Carbon instance, using the provided format.

If no format is specified 'd.m.Y H:i:s' will be used.

use Morningtrain\DataTransferObjectCasters\Casters\DateCaster;

class DTO extends DataTransferObject
{
    #[CastWith(DateCaster::class, format: 'Y-m-d')]
    public Carbon $date;
}

Int

The IntCaster casts the provided value to an integer using (int) cast.

Trim

The TrimCaster will trim the provided value, so no whitespace remains around the value.

UppercaseFirst

The UppercaseFirstCaster will uppercase the first letter of the provided value, similar to php's ucfirst function.

Optionally, the caster can lowercase the rest of the string, like so.

use Morningtrain\DataTransferObjectCasters\Casters\UppercaseFirstCaster;

class DTO extends DataTransferObject
{
    #[CastWith(UppercaseFirstCaster::class, lower: true)]
    public string $ucFirstString;
}

If the provided value is not a string, it will return the provided value.

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.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-19