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

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

uvarats/dto
===========

Lightweight library for creating PHP 8 dto with constructor promoted fields

v0.3.0(3y ago)02.7kGPL-3.0-or-laterPHPPHP &gt;=8.2

Since Mar 6Pushed 3y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Lightweight DTO library for PHP 8 constructor-promoted properties.
==================================================================

[](#lightweight-dto-library-for-php-8-constructor-promoted-properties)

Initially this package was developed for internal use, but then I was decided to publish.

Install:

```
composer require uvarats/dto

```

Requirements: PHP 8.2

Supported:

- DTO populating
- Enum properties
- Array of DTO

Usage:
======

[](#usage)

Just extend Data class by your DTO.

Then just create DTO object via YourDto::from($data) where $data is your array with data. This array must have same mapping as class fields (no 'data' at the root of array).

Example:

```
final class LoginDto extends Data
{
    public function __construct(
        public readonly ?string $username = null,
        public readonly ?string $password = null,
    )
    {
    }
}
```

Then:

```
$data = [
    'username' => 'some_user',
    'password' => '123456'
];

$dto = LoginDto::from($data);

// Collection

$data = [
    [
        'username' => 'some_user',
        'password' => '123456'
    ],
    [
        'username' => 'some_user',
        'password' => '123456'
    ],
];

$dtos = LoginDto::collection($data);
```

Also supported nested data and enums:

```
enum State: string
{
    case NEW = 'new';
    case UNDER_MODERATION = 'under_moderation';
    case PUBLISHED = 'published';
}

final class AuthorDto extends Data
{
    public function __construct(
        public readonly string $userId,
        public readonly string $username,
    )
    {
    }
}

final class ExampleDto extends Data
{
    public function __construct(
        public readonly string $name,
        public readonly State $state,
        public readonly AuthorDto $author
    )
    {
    }
}
```

```
$data = [
    'name' => 'Some name',
    'state' => 'new',
    'author' => [
        'userId' => '232',
        'username' => 'user',
    ]
];
```

If not nullable property without default value does not present in array, an exception will be thrown. Constructor properties must be strictly typed. Union and intersection are prohibited.

```
final class TestDto extends Data
{
    public function __construct(
        public $name,                           // Exception
        public string|array $id,                // Exception
        public callable&iterable $caliterable   // Also exception
    )
    {
    }
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Every ~19 days

Total

4

Last Release

1109d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d4af1d00347acca68d5fb7ed3d33ba4b7947c9c773580766ceda27377b250a?d=identicon)[uvarats](/maintainers/uvarats)

---

Top Contributors

[![uvarats](https://avatars.githubusercontent.com/u/77531256?v=4)](https://github.com/uvarats "uvarats (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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