PHPackages                             nandan108/dto-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nandan108/dto-toolkit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nandan108/dto-toolkit
=====================

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

v1.4.4(2mo ago)1331MITPHPPHP &gt;=8.1 &lt;8.6CI passing

Since Apr 11Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Nandan108/dto-toolkit)[ Packagist](https://packagist.org/packages/nandan108/dto-toolkit)[ RSS](/packages/nandan108-dto-toolkit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (25)Used By (1)

DTO Toolkit Core
================

[](#dto-toolkit-core)

[![CI](https://github.com/nandan108/dto-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/nandan108/dto-toolkit/actions/workflows/ci.yml/badge.svg)[![Coverage](https://camo.githubusercontent.com/51d34283dcb3e05a96d154bac7c02fefd48a374dfdb674f9c8b420d7cf6cf1b0/68747470733a2f2f636f6465636f762e696f2f67682f6e616e64616e3130382f64746f2d746f6f6c6b69742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://camo.githubusercontent.com/51d34283dcb3e05a96d154bac7c02fefd48a374dfdb674f9c8b420d7cf6cf1b0/68747470733a2f2f636f6465636f762e696f2f67682f6e616e64616e3130382f64746f2d746f6f6c6b69742f6272616e63682f6d61696e2f67726170682f62616467652e737667)[![Style](https://camo.githubusercontent.com/77a781eb39a9e5a05b2ca0fb24ed710d9ba4e063d4077b5a622535447c5d4790/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374796c652d7068702d2d63732d2d66697865722d627269676874677265656e)](https://camo.githubusercontent.com/77a781eb39a9e5a05b2ca0fb24ed710d9ba4e063d4077b5a622535447c5d4790/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374796c652d7068702d2d63732d2d66697865722d627269676874677265656e)[![Packagist](https://camo.githubusercontent.com/c2c8c0ebd5cbfe47bcfdcfd770e4ba4539f3e447aadc63da3b46a27d419ff322/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e616e64616e3130382f64746f2d746f6f6c6b6974)](https://camo.githubusercontent.com/c2c8c0ebd5cbfe47bcfdcfd770e4ba4539f3e447aadc63da3b46a27d419ff322/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e616e64616e3130382f64746f2d746f6f6c6b6974)

✅ Requires PHP 8.1–8.5

DTO Toolkit Core is a lightweight, framework-agnostic library for **processing** Data Transfer Objects (DTOs) in PHP. It provides a unified model for normalization, validation, transformation, and export — with first-class support for nested structures and context-aware execution.

The API is fully declarative and attribute-driven: casters, validators, and control-flow modifiers compose into explicit processing pipelines that are JIT-compiled into efficient runtime chains, without coupling to any specific framework.

DTO Toolkit treats data transformation as a lifecycle, not a side effect.

✨ Features
----------

[](#-features)

- 🧱 Conceptually lightweight, framework-agnostic core
- 🏷️ Attribute-based processing pipelines with explicit control flow
- 🎯 Optional validation and normalization layers
- 🔄 Easily transform between DTOs and entities/models
- 🧬 First-class support for nested DTO processing (inbound and outbound), with consistent context propagation
- 🧩 Designed to work with pluggable [framework adapters](#adapter-packages) (Laravel, Symfony, etc.)

📦 Installation
--------------

[](#-installation)

```
composer require nandan108/dto-toolkit
```

🚀 Quick Start
-------------

[](#-quick-start)

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

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

final class MyEntity
{
    public ?string $name = null;
}

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

// Transform into an entity (optionally recursive)
$entity = $dto->exportToEntity(MyEntity::class, recursive: true);
```

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

---

📦 Core Namespace
----------------

[](#-core-namespace)

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

- `Nandan108\DtoToolkit\Core\FullDto`
- `Nandan108\DtoToolkit\Core\CastTo`
- `Nandan108\DtoToolkit\Core\Assert`

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

---

📚 Documentation
---------------

[](#-documentation)

- [DTO Fundamentals](docs/DtoFundamentals.md) – what DTOs are, why they matter, and how to use them in modern PHP
- [Casting](docs/Casting.md) – how casting works and how to write your own
- [Attributes](docs/Attributes.md) - List of attributes
- [Lifecycle](docs/DtoLifecycle.md) – Understanding the lifecycle of a DTO
- [Lifecycle Hooks](docs/Hooks.md) – customize behavior with `postLoad()` and `preOutput()`
- [Toolkit Comparison](docs/Comparison.md) – see how this toolkit compares to other PHP DTO/mapping libraries
- [Processing in detail](docs/Processing.md) — Validating and Transforming Data Through Nodes
- [Built-In Core Casters](docs/BuiltInCasters.md) — Full list of available `CastTo\*` casters
- [Built-In Core Validators](docs/BuiltInValidators.md) — list of available `Validate\*` validators *(more are planned)*
- [Built-In Core Modifiers](docs/BuiltInModifiers.md) — Full list of available `Mod\*` chain modifiers
- [Dependency Injection](docs/DI.md)
- [I18n](docs/i18n.md) — locale-aware casters and error-message translation setup
- Writing Adapters *(planned)*

---

🏃 Runtime &amp; Concurrency
---------------------------

[](#-runtime--concurrency)

- Multi-threaded runtimes (`pthreads` / `parallel`) are not supported by the core and are not planned to be.
- Execution context storage is abstracted behind `ContextStorageInterface`, allowing adapters to provide execution-local storage (e.g. for fibers/coroutines/tasks).
- Fiber/event-loop runtimes (Swoole, RoadRunner, ReactPHP, etc.) are **not officially supported yet**.
- Adapter hooks exist, but full concurrent-runtime support still requires synchronization guarantees around cache warm-up paths, which are not implemented yet.

---

🔒 Immutability &amp; Value Objects
----------------------------------

[](#-immutability--value-objects)

DTO Toolkit is **not an immutable DTO library**.

DTOs in DTOT are **mutable by design** and act as **transformation builders**: they ingest raw input, apply validation and normalization, and produce clean, structured output. This mutability is what enables DTOT’s dynamic processing model (casting chains, modifiers, context-aware behavior, recursive imports/exports).

That said, DTOT **plays very well with immutable objects**.

While DTOs themselves are mutable, DTOT is designed to **export into immutable value objects or entities** via constructor-based instantiation. This allows you to use DTOT as a *builder* for immutable domain models (value objects), without compromising immutability where it matters.

👉 If you’re looking for *immutability at the DTO layer itself*, DTOT may not be the right fit.
👉 If you want **powerful, declarative transformation pipelines to produce immutable domain objects**, DTOT is a strong match.

---

🧩 Adapter Packages
------------------------------------------------------------

[](#-adapter-packages)

- Laravel Adapter: [`nandan108/dto-toolkit-laravel`](https://github.com/nandan108/dto-toolkit-laravel) *(coming soon)*
- Symfony Adapter: [`nandan108/dto-toolkit-symfony`](https://github.com/nandan108/dto-toolkit-symfony) *(planned)*

Adapters will provide support for:

- Framework-compatible error handling and translations, for both validators and casters
- `fromRequest()` for DTO hydration from HTTP requests
- `exportToEntity()` 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 &amp; Quality
-----------------------

[](#-testing--quality)

- 100% test coverage using PHPUnit
- Psalm level 1 (maximum strictness)
- Code style enforced with [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer):
    - Based on the `@Symfony` rule set
    - Aligned `=>` for better readability
    - Disallows implicit loose comparisons (`==`, `!=`) except in explicit operator-semantics helpers
- Commit message style: conventional, with details if any

### CI Checks

[](#ci-checks)

GitHub Actions (`.github/workflows/ci.yml`) runs:

- `phpunit` on PHP `8.1` to `8.5`
- `php-cs-fixer --dry-run` (on one matrix leg)
- `psalm` (on one matrix leg)
- `composer api-audit-strict` (on one matrix leg)

### Run Locally Before Push

[](#run-locally-before-push)

```
composer test
composer psalm
composer cs-fix
composer api-audit-strict
```

Optional: install repository Git hooks (pre-commit + pre-push):

```
./scripts/setup-hooks.sh
```

Installed `pre-commit` runs staged-file PHP-CS-Fixer checks and then optional local extension hook `.git/hooks/pre-commit.local` if present. Installed `pre-push` runs `composer api-audit-strict`, PHPUnit, Psalm, and then optional local extension hook `.git/hooks/pre-push.local` if present.

---

🤝 Contributing
--------------

[](#-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
-------------------

[](#-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](https://github.com/nandan108)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance83

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Recently: every ~3 days

Total

24

Last Release

84d ago

Major Versions

v0.11.0 → v1.0.02026-01-25

PHP version history (3 changes)v0.1.0PHP ^8.1

v0.4.1PHP &gt;=8.1 &lt;8.5

v0.9.0PHP &gt;=8.1 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/024c3beb5cbe22cd3e3f3db6938cf893c09d0b3b90076e2e1566530cd0693372?d=identicon)[Nandan108](/maintainers/Nandan108)

---

Top Contributors

[![Nandan108](https://avatars.githubusercontent.com/u/354944?v=4)](https://github.com/Nandan108 "Nandan108 (79 commits)")

---

Tags

attributesdata-mappingdata-normalizationdata-validationdtoframework-agnosticopen-sourcephpphp8type-casting

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nandan108-dto-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/nandan108-dto-toolkit/health.svg)](https://phpackages.com/packages/nandan108-dto-toolkit)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
