PHPackages                             jdcode/dto-php - 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. jdcode/dto-php

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

jdcode/dto-php
==============

Simple and flexible Data Transfer Object library with validations

v1.0.0(11mo ago)050MITPHPPHP &gt;=8.0

Since Jun 22Pushed 11mo agoCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

[![PHP version](https://camo.githubusercontent.com/6913801024bb6087176dec5fdb59388730a49b167cbb013222a7acbaecb48b7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)

Dto-Php
=======

[](#dto-php)

Simple and flexible Data Transfer Object library with validations

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require jdcode/dto-php

```

Usage
-----

[](#usage)

Class Dto

```
use JDCode\DtoPhp\DtoPhp;

class StoreUserDto extends DtoPhp
{
    public string $username;
    public string $password;
    public int $age;
}
```

In your UseCase class

```
$dto = new StoreUserDto([
    'username' => 'admin',
    'password => '123456'
    'age' => 99
]);
```

Validation
----------

[](#validation)

Currently it only has 3 basic validations

Class Dto

```
use JDCode\DtoPhp\DtoPhp;
use JDCode\DtoPhp\Validations\MinLength;
use JDCode\DtoPhp\Validations\MaxLength;
use JDCode\DtoPhp\Validations\Email;

class StoreUserDto extends DtoPhp
{
    #[MinLength(length: 3), MaxLength(length: 10)]
    public string $username;

    public string $password;

    #[Email]
    public string $email

    public int $age;
}
```

You can use `$dto->validated()` to know if the validation was correct and `$dto->getErrors()` to get the error messages.

Type Class object
-----------------

[](#type-class-object)

If your property type is a DTO object, just placing it will automatically cast it.

Class Dto

```
use JDCode\DtoPhp\DtoPhp;

class StoreUserDto extends DtoPhp
{
    public string $username;
    public string $password;
    public int $age;
    public RoleDto $role
}
```

```
use JDCode\DtoPhp\DtoPhp;

class RoleDto extends DtoPhp
{
    public int $id;
    public string $name;
}
```

In your UseCase class

```
$dto = new StoreUserDto([
    'username' => 'admin',
    'password => '123456'
    'age' => 99,
    'roles' => [
        'id' => 1,
        'name' => 'Administrator'
    ]
]);
```

Array Object
------------

[](#array-object)

If you need an object array, just by placing the corresponding attribute you will get your object array.

```
use JDCode\DtoPhp\DtoPhp;

class RoleDto extends DtoPhp
{
    public int $id;
    public string $name;
}
```

```
use JDCode\DtoPhp\DtoPhp;
use JDCode\DtoPhp\Casters\CastArrayWithObject;

class StoreUserDto extends DtoPhp
{
    public string $username;
    public string $password;

    #[CastArrayWithObject(Role::class)]
    public array $roles;
}
```

In your UseCase class

```
$dto = new StoreUserDto([
    'username' => 'admin',
    'password => '123456'
    'age' => 99,
    'roles' => [
       [
            'id' => 1,
            'name' => 'Administrator'
       ],
       [
            'id' => 2,
            'name' => 'Moderator'
       ]
    ]
]);

var_dump($dto->roles) // returns RoleDto[]
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance52

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

330d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b3cc9f6cda612d362189d353dc495112434e8f94fe08d6de20fffd3f758ecd3?d=identicon)[JDCode97](/maintainers/JDCode97)

---

Top Contributors

[![JDCode97](https://avatars.githubusercontent.com/u/207485084?v=4)](https://github.com/JDCode97 "JDCode97 (1 commits)")

### Embed Badge

![Health badge](/badges/jdcode-dto-php/health.svg)

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

###  Alternatives

[botman/driver-facebook

Facebook Messenger driver for BotMan

71301.6k6](/packages/botman-driver-facebook)

PHPackages © 2026

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