pepperfm/ssd-for-laravel
最新稳定版本:0.2.0
Composer 安装命令:
composer require pepperfm/ssd-for-laravel
包简介
Simple Slim DTO
README 文档
README
Easily describe your data with minimal boilerplate. No magic, no transformations — just pure, readable schema.
Typehint your data in camelCase. No hidden transformations or data mutations. Clean, readable, and intuitive code. Just a simple class to map your data, following the KISS💋 principle.
Tip
Installation
composer r pepperfm/ssd-for-laravel
Usage
Extends your class from BaseDto and define your data
class ResponseWrapperDto extends BaseDto { public array $data; public array $links; public array $metaData; }
Base case
You can create the object like this:
ResponseWrapperDto::make([ 'data' => $response['data'], 'links' => $response['links'], 'meta_data' => $response['meta'], ])
use Pepperfm\DonationAlerts\Attributes\ToIterable; class ResponseWrapperDto extends BaseDto { #[ToIterable(ResponseDataDto::class)] public array $data; public array $links; public array $metaData; }
Output:
/** * @var array<array-key, ResponseDataDto> $data */ $data = $dto->data;
Extended cases
ResponseWrapperDto::make(literal( data: $response['data'], links: $response['links'], meta: $response['meta'], ))
new ResponseWrapperDto( data: $response['data'], links: $response['links'], meta: $response['meta'], )
ResponseWrapperDto::make([ 'data' => $response['data'], 'links' => $response['links'], 'meta' => $response['meta'], ])
new ResponseWrapperDto([ 'data' => $response['data'], 'links' => $response['links'], 'meta' => $response['meta'], ])
Warning
Only for collections (non-native array)
use Pepperfm\DonationAlerts\Attributes\ToIterable; class ResponseWrapperDto extends BaseDto { #[ToIterable(ResponseDataDto::class, \Illuminate\Database\Eloquent\Collection::class)] public \Illuminate\Support\Collection $data; public array $links; public array $metaData; }
Output:
/** @var \Illuminate\Database\Eloquent\Collection<array-key, ResponseDataDto> $data */ $data = $dto->data;
Note
In this version this package will transform any snake_case variables to camelCase
I started with this because I like this approach
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email Damon3453@yandex.ru instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
统计信息
- 总下载量: 14.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-25