承接 nandan108/dto-toolkit 相关项目开发

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

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

nandan108/dto-toolkit

最新稳定版本:v0.9.0

Composer 安装命令:

composer require nandan108/dto-toolkit

包简介

A modern, framework-agnostic PHP 8.1+ DTO system with attribute-driven data normalization and mapping to entities or arrays.

README 文档

README

CI Coverage Style Packagist

✅ Requires PHP 8.1–8.5

DTO Toolkit Core is a lightweight, framework-agnostic library for defining, transforming, and (soon) validating Data Transfer Objects (DTOs) in PHP.

It offers a clean, declarative API powered by attributes — handling normalization, casting, and output shaping — all without coupling to any specific framework.

Casters, modifiers, and validators are composed into a fully declarative transformation DSL, JIT-compiled into efficient processing chains at runtime.

✨ Features

  • 🧱 Minimal and framework-agnostic
  • 🏷️ Attribute-based processing system with flexible resolution
  • 🎯 Optional validation and normalization layers
  • 🔄 Easily transform between DTOs and entities/models
  • 🧩 Designed to work with pluggable framework adapters (Laravel, Symfony, etc.)

📦 Installation

composer require nandan108/dto-toolkit

🚀 Quick Start

use Nandan108\DtoToolkit\Core\{FullDto, CastTo};

// FullDto includes all standard traits (CreatesFromArray, NormalizesFromAttributes, ExportsToEntity)
class MyDto extends FullDto {
    #[CastTo\Trimmed()]
    public ?string $name = null;
}

// Build DTO from array
$dto = MyDto::newFromArray(['name' => '  Alice  ']);

// Transform into an entity
$entity = $dto->toEntity();

Use a framework adapter (e.g. Symfony or Laravel) to unlock request/response integration and validation support.

📦 Core Namespace

If you're not using a framework, start with:

  • Nandan108\DtoToolkit\Core\FullDto
  • Nandan108\DtoToolkit\Core\CastTo

These provide a convenient, framework-free entry point with all standard functionality included.

📚 Documentation

🧩 Adapter Packages

Adapters will provide support for:

  • Framework-compatible error handling and translations, for both validators and casters
  • fromRequest() for DTO hydration from HTTP requests
  • toEntity() or toModel() adapter-specific hydration
  • toResponse() generation
  • DI for class-based casters resolution
  • Graceful handling of validation and casting exceptions in HTTP contexts, with standardized API error responses

🧪 Testing & Quality

  • 100% test coverage using PHPUnit
  • Psalm level 3
  • Code style enforced with PHP-CS-Fixer:
    • Based on the @Symfony rule set
    • Aligned => for better readability
    • Disallows implicit loose comparisons (==, !=)
  • Commit message style: conventional, with details if any

🤝 Contributing

Bug reports, ideas, and contributions welcome! This project aims to stay lean, clean, and focused. If you're building an adapter or extending the system, feel free to open a discussion or issue.

🧭 Design Philosophy

This toolkit is built on a simple idea: do the most work with the least number of moving parts.

It favors:

  • Declarative code over procedural boilerplate
  • Clever, expressive syntax without falling into obfuscation
  • Minimalism with power — clean by default, extensible when needed
  • Framework-agnostic design with optional adapters that integrate smoothly when needed
  • Zero magic in the core — everything is traceable, explicit, and predictable
  • Opt-in magic in adapters — for just the right touch of convenience when working with frameworks
  • Separation of concerns and composability — inspired by the Unix philosophy of doing one thing well
  • Performance-conscious by design — DTOs should feel lightweight and fast to use, even in large batch transformations.

Verbose code is a tax on your time. This toolkit aims to keep things sharp, concise, and purposeful — so you can focus on what matters.

MIT License © nandan108

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-11