承接 pepperfm/ssd-for-laravel 相关项目开发

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

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

pepperfm/ssd-for-laravel

Composer 安装命令:

composer require pepperfm/ssd-for-laravel

包简介

Simple Slim DTO

README 文档

README

Latest Version on Packagist Total Downloads on Packagist GitHub Actions

Simple Slim DTO helps you describe small DTO classes for Laravel responses, array payloads, and typed data wrappers.

The package maps array-like input into public typed properties, supports snake_case and camelCase keys, casts nested DTOs, converts iterable items, and serializes DTOs back to arrays or JSON.

Tip

Full Package Description

Requirements

  • PHP ^8.4

Installation

composer require pepperfm/ssd-for-laravel

Basic Usage

Extend BaseDto and describe the payload with public typed properties.

use Pepperfm\Ssd\BaseDto;

class ResponseWrapperDto extends BaseDto
{
    public array $data;

    public LinksDto $links;

    public MetaDto $meta;
}

Create DTOs from arrays, objects, Arrayable, Traversable, or named arguments.

$dto = ResponseWrapperDto::make([
    'data' => $response['data'],
    'links' => $response['links'],
    'meta' => $response['meta'],
]);
$dto = new ResponseWrapperDto(
    data: $response['data'],
    links: $response['links'],
    meta: $response['meta'],
);

Nested DTO properties are cast automatically.

use Pepperfm\Ssd\BaseDto;

class LinksDto extends BaseDto
{
    public ?string $first = null;

    public ?string $last = null;

    public ?string $prev = null;

    public ?string $next = null;
}

class MetaDto extends BaseDto
{
    public int $currentPage;

    public int $total;
}

Iterable Casting

Use ToIterable when a property contains a list of items.

The first argument is the collection type. Use ToIterable::ARRAY for a native array. The second argument is optional and defines the item type.

use Pepperfm\Ssd\Attributes\ToIterable;
use Pepperfm\Ssd\BaseDto;

class ResponseDataDto extends BaseDto
{
    public string $id;

    public string $name;
}

class ResponseWrapperDto extends BaseDto
{
    #[ToIterable(ToIterable::ARRAY, ResponseDataDto::class)]
    public array $data = [];
}
/** @var array<array-key, ResponseDataDto> $items */
$items = $dto->data;

For Laravel collections, pass the collection class as the first argument.

use Illuminate\Support\Collection;
use Pepperfm\Ssd\Attributes\ToIterable;
use Pepperfm\Ssd\BaseDto;

class ResponseWrapperDto extends BaseDto
{
    #[ToIterable(Collection::class, ResponseDataDto::class)]
    public Collection $data;
}
/** @var Collection<array-key, ResponseDataDto> $items */
$items = $dto->data;

If the item type is omitted, iterable items are kept as-is.

use Pepperfm\Ssd\Attributes\ToIterable;
use Pepperfm\Ssd\BaseDto;

class TagsDto extends BaseDto
{
    #[ToIterable(ToIterable::ARRAY)]
    public array $tags = [];
}

The item type may be another BaseDto class or any class that can be instantiated from one value.

Key Mapping

Input keys can be camelCase or snake_case. Output keys are camelCase by default. Use MapName when the external key must be explicit.

use Pepperfm\Ssd\Attributes\MapName;
use Pepperfm\Ssd\BaseDto;

class UserDto extends BaseDto
{
    #[MapName('external_name')]
    public string $displayName;
}
$dto = UserDto::make([
    'external_name' => 'Ada',
]);

$dto->displayName; // Ada
$dto->external_name; // Ada
$dto->toArray(); // ['external_name' => 'Ada']

Collections and Helpers

Convert many payloads into DTO instances with collect().

$items = ResponseDataDto::collect($response['data']);

Use only() and except() on serialized DTO output.

$dto->only('data', 'meta');
$dto->except('links');

Serialization

$dto->toArray();
$dto->jsonSerialize();
json_encode($dto);

Testing

composer test
composer lint

Changelog

Please see CHANGELOG for more information about 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.

pepperfm/ssd-for-laravel 适用场景与选型建议

pepperfm/ssd-for-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33.71k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「schema」 「Simple」 「typehint」 「dto」 「pepperfm」 「ssd-for-laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pepperfm/ssd-for-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pepperfm/ssd-for-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 pepperfm/ssd-for-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-25