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

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

maduser/argon-dto
=================

A PHP package for Data Transfer Objects (DTOs)

v1.0.0(11mo ago)0231MITPHPPHP ^8.2CI passing

Since Jul 27Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/judus/argon-dto)[ Packagist](https://packagist.org/packages/maduser/argon-dto)[ RSS](/packages/maduser-argon-dto/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (7)Versions (3)Used By (1)

[![PHP](https://camo.githubusercontent.com/ce3e396e4f1bbbd326f628872a1414656d28065f2712cda0868d8eff07320aec/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322b2d626c7565)](https://www.php.net/)[![Build](https://github.com/judus/argon-dto/actions/workflows/php.yml/badge.svg)](https://github.com/judus/argon-dto/actions)[![codecov](https://camo.githubusercontent.com/a698f973f0a055bd9ccc12bdd4497c560bb3c4cbaaf6ff204d6905337e1164a4/68747470733a2f2f636f6465636f762e696f2f67682f6a756475732f6172676f6e2d64746f2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/judus/argon-dto)[![Psalm Level](https://camo.githubusercontent.com/037072a00158af68186845ca109d53ed6c251fab1303754d6652043017f41927/68747470733a2f2f73686570686572642e6465762f6769746875622f6a756475732f6172676f6e2d64746f2f636f7665726167652e737667)](https://shepherd.dev/github/judus/argon-dto)[![Code Style](https://camo.githubusercontent.com/3228be89f864906adf15243b35e8c354bb3fe91c1c02f070563c5cfbef9f36cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5053522d2d31322d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-12/)[![Latest Version](https://camo.githubusercontent.com/99bb41601fe3420a0914477e7799cd6c0e7944759d377d55ca22285aed6ff446/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6164757365722f6172676f6e2d64746f2e737667)](https://packagist.org/packages/maduser/argon-dto)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Argon DTO
=========

[](#argon-dto)

A lightweight PHP DTO implementation with support for array and JSON hydration, serialization, and optional auto-mapping using field constants. Reflection at runtime is avoided by design.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Composer

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

[](#installation)

```
composer require maduser/argon-dto
```

Overview
--------

[](#overview)

This package provides:

- A base `AbstractDTO` class for immutable data transfer objects.
- Optional auto-mapping via `AutoMappableInterface` and `AutoMap`.
- Consistent serialization via `toArray()` and `toJson()`.
- Custom exceptions for misconfiguration or serialization errors.

Usage
-----

[](#usage)

### Simple DTO

[](#simple-dto)

For a basic DTO, just extend `AbstractDTO`:

```
use Maduser\Argon\DTO\AbstractDTO;

final class ProductDTO extends AbstractDTO
{
    public function __construct(
        public readonly int $id,
        public readonly string $name
    ) {}
}

$dto = new ProductDTO(1, 'Gadget');
```

### Auto-Mapping DTO

[](#auto-mapping-dto)

If you want array-to-constructor mapping without manually unpacking arrays:

```
use Maduser\Argon\DTO\AbstractDTO;
use Maduser\Argon\DTO\Contracts\AutoMappableInterface;
use Maduser\Argon\DTO\Traits\AutoMap;

final class UserDTO extends AbstractDTO implements AutoMappableInterface
{
    use AutoMap;

    public const MAPPABLE_FIELDS = ['id', 'name'];

    public function __construct(
        public readonly int $id,
        public readonly string $name
    ) {}
}
```

You can then hydrate from arrays or JSON:

```
$dto = UserDTO::fromArray(['id' => 1, 'name' => 'Alice']);
$dto = UserDTO::fromJson('{"id":1,"name":"Alice"}');
```

### Accessing Data

[](#accessing-data)

```
$array = $dto->toArray();
$json = $dto->toJson();
```

### Mapping Logic

[](#mapping-logic)

If your DTO implements `AutoMappableInterface`, you must define a `mapFromArray()` method. You can implement this manually or use the provided `AutoMap` trait. The trait uses `MAPPABLE_FIELDS` to determine which keys to extract from the input array and in what order:

```
public static function mapFromArray(array $data): array
{
    $fqcn = static::class;

    if (!defined("$fqcn::MAPPABLE_FIELDS")) {
        throw DTOMappingException::missingMap($fqcn);
    }

    /** @var list $fields */
    $fields = constant("$fqcn::MAPPABLE_FIELDS");

    return array_map(
        static function (string $key) use ($data, $fqcn): mixed {
            if (!array_key_exists($key, $data)) {
                throw DTOMappingException::missingField($key, $fqcn);
            }
            return $data[$key];
        },
        $fields
    );
}
```

- The order of keys in the input array is irrelevant.
- Extra keys in the input array are ignored.

Error Handling
--------------

[](#error-handling)

- `DTOConfigurationException` – DTO lacks required mapping behavior.
- `DTOMappingException` – Missing fields or invalid `MAPPABLE_FIELDS`.
- `DTOSerializationException` – JSON encoding/decoding failures.

Testing
-------

[](#testing)

```
vendor/bin/phpunit
vendor/bin/psalm
vendor/bin/phpcs
```

License
=======

[](#license)

MIT

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance51

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

342d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7fb9da5a15010d335622bf9f465a32ef79c8d1cffcd139c2a9114736b72e2c13?d=identicon)[jdu](/maintainers/jdu)

---

Top Contributors

[![judus](https://avatars.githubusercontent.com/u/1478654?v=4)](https://github.com/judus "judus (13 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[opensoft/rollout

Feature switches or flags for PHP

2611.9M5](/packages/opensoft-rollout)[sidroberts/phalcon-cron

Cron component for Phalcon.

82153.4k](/packages/sidroberts-phalcon-cron)[faonni/module-breadcrumbs

Extension add breadcrumbs to pages in Magento 2 that by default do not have breadcrumbs.

1515.3k](/packages/faonni-module-breadcrumbs)

PHPackages © 2026

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