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

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

idoit/dto
=========

i-doit DTO package provides infrastructure to work with DTO

v1.0.0(1y ago)01.2k↓53.3%MITPHPPHP ^8.1

Since Jun 30Pushed 1y agoCompare

[ Source](https://github.com/i-doit/dto)[ Packagist](https://packagist.org/packages/idoit/dto)[ RSS](/packages/idoit-dto/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

i-doit DTO
==========

[](#i-doit-dto)

This library provides methods to simplify working with DTOs in PHP.

It provides serialization and validation helpers to define behaviour of the DTO via attributes.

Setup
-----

[](#setup)

Require library via composer

```
composer require idoit/dto

```

Usage
-----

[](#usage)

For the following examples we will use this DTO class that defines some public readonly properpties. Please note the attributes which will be used for validation and, in case of `DateFormat`, serialization:

```
use Idoit\Dto\Validation\IsNull;
use Idoit\Dto\Validation\OrX;
use Idoit\Dto\Validation\PositiveInteger;
use Idoit\Dto\Validation\Required;
use Idoit\Dto\Serialization\DateFormat;

/**
 * Object read DTO. Will be returned when reading objects via processor.
 */
class MyDto
{
    public function __construct(
        #[Required]
        #[PositiveInteger]
        public readonly int $id = 0,

        public readonly string|null $title = null,

        #[OrX(new IsNull(), new PositiveInteger())]
        public readonly int|null $type = null,

        #[DateFormat]
        public readonly DateTime|null $created = null
        // ...
    ) {
    }
}
```

### Validation

[](#validation)

In order to validate this DTO, you can use `Validation::validate($dto);`, like so:

```
use Idoit\Dto\Validation\Validation;

$dto = new MyDto(5, 'My Title', -1); // Has a negative type, but SHOULD be null or positive.

$errors = Validation::validate($dto);
/*
 * '$errors' will contain the following data:
 *
 * array (
 *   0 => \Idoit\Dto\Validation\ValidationMessage::__set_state(array(
 *     'path' =>
 *       array (
 *         0 => 'type'
 *       ),
 *     'message' => 'The value must be a null.'
 *   )),
 *   1 => \Idoit\Dto\Validation\ValidationMessage::__set_state(array(
 *     'path' =>
 *       array (
 *         0 => 'type'
 *       ),
 *     'message' => 'The value must be positive number.'
 *   ))
 * )
 */
```

If you need specific logic for validation you can simply create your own classes to do so. Simply implement the `\Idoit\Dto\Validation\ValidatorInterface` interface and write your own `validate` method.

### Serialization

[](#serialization)

We can use `Serializer` to convert JSON structures to DTOs and the other way around:

```
$dto = \Idoit\Dto\Serialization\Serializer::fromJson(MyDto::class, [
    'id' => 123,
    'title' => 'Silvester',
    'type' => 2,
    'created' => '2025-12-31T00:00:00+00:00'
]);
/*
 * '$dto' will contain the following data:
 *
 * \MyDto::__set_state(array(
 *    'id' => 123,
 *    'title' => 'Silvester',
 *    'type' => 2,
 *    'created' =>
 *   \DateTime::__set_state(array(
 *      'date' => '2025-12-31 00:00:00.000000',
 *      'timezone_type' => 1,
 *      'timezone' => '+00:00'
 *   ))
 * ))
 */

$array = \Idoit\Dto\Serialization\Serializer::toJSON($dto);
/**
 * '$array' will contain the following data:
 *
 * array (
 *   'id' => 123,
 *   'title' => 'Silvester',
 *   'type' => 2,
 *   'created' => '2025-12-31T00:00:00+00:00'
 * )
 */
```

If you need specific logic for serialization you can simply create your own classes to do so. Simply extend the abstract `Idoit\Dto\Serialization\Format` class and implement your own `toJson` and `fromJson` methods.

**Please note** that the validation will not be executed, when serializing data.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance50

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

368d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/771368?v=4)[idoit](/maintainers/idoit)[@idoit](https://github.com/idoit)

---

Top Contributors

[![leonardfischer](https://avatars.githubusercontent.com/u/399835?v=4)](https://github.com/leonardfischer "leonardfischer (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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