PHPackages                             phprise/data-transfer-object - 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. phprise/data-transfer-object

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

phprise/data-transfer-object
============================

The initial Data Transfer Object to generate your own DTOs applying OTAKU philosophy

v1.1.3(5mo ago)0205MITPHP

Since Jan 7Pushed 5mo agoCompare

[ Source](https://github.com/phprise-foundation/data-transfer-object)[ Packagist](https://packagist.org/packages/phprise/data-transfer-object)[ RSS](/packages/phprise-data-transfer-object/feed)WikiDiscussions 1.x Synced 3w ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (5)

Data Transfer Object
====================

[](#data-transfer-object)

A strict, no-nonsense Data Transfer Object (DTO) library for PHP, following the **OTAKU Philosophy**.

It simplifies data transport between layers of your application, ensuring type safety and automatic mapping between `snake_case` (common in databases/APIs) and `camelCase` (standard in PHP).

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

[](#installation)

```
composer require phprise/data-transfer-object
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Define your DTO by extending `Phprise\DataTransferObject\TransferObject` and adding public typed properties.

```
use Phprise\DataTransferObject\TransferObject;

class UserDto extends TransferObject
{
    public string $name;
    public int $age;
}

// Create from array
$data = ['name' => 'John Doe', 'age' => 30];
$dto = UserDto::fromArray($data);

echo $dto->name; // John Doe
echo $dto->age;  // 30

// Convert back to array
$array = $dto->toArray();
// ['name' => 'John Doe', 'age' => 30]
```

### Snake Case Magic

[](#snake-case-magic)

The library automatically handles conversion between `snake_case` keys and `camelCase` properties.

```
class UserProfileDto extends TransferObject
{
    public string $firstName;
    public string $lastName;
}

$data = [
    'first_name' => 'Alice',
    'last_name' => 'Wonderland',
];

$dto = UserProfileDto::fromArray($data);

echo $dto->firstName; // Alice

// Export as snake_case array
$snakeArray = $dto->toSnakeCaseArray();
// ['first_name' => 'Alice', 'last_name' => 'Wonderland']
```

### Nested DTOs

[](#nested-dtos)

You can nest DTOs. The library will recursively hydrate them.

```
class AddressDto extends TransferObject
{
    public string $street;
    public string $city;
}

class CustomerDto extends TransferObject
{
    public string $name;
    public AddressDto $address;
}

$data = [
    'name' => 'Bob',
    'address' => [
        'street' => '123 Maker Lane',
        'city' => 'Buildtown',
    ],
];

$dto = CustomerDto::fromArray($data);

echo $dto->address->city; // Buildtown
```

### DateTime Support

[](#datetime-support)

Strings in standard formats (ISO 8601 / RFC 3339) are automatically converted to `DateTimeImmutable` objects if typed as such.

```
class EventDto extends TransferObject
{
    public string $title;
    public \DateTimeImmutable $date;
}

$data = [
    'title' => 'Conference',
    'date' => '2023-10-27T10:00:00+00:00',
];

$dto = EventDto::fromArray($data);
echo $dto->date->format('Y-m-d'); // 2023-10-27
```

### JSON Serialization

[](#json-serialization)

```
$json = $dto->toJson();
// or
$jsonSnake = $dto->toSnakeCaseJson();

$dto = UserDto::fromJson($json);
```

Philosophy
----------

[](#philosophy)

We follow **The OTAKU Manifesto: Fluid Structure Design**.

1. **O** - Own your Discipline (Be strict with yourself)
2. **T** - Tools for Composition (Compose like Unix)
3. **A** - Armor the Core (Protect the heart of the business)
4. **K** - Keep Infrastructure Silent (Infrastructure is just a detail)
5. **U** - Universal Language &amp; Contracts (Speak the user's language via clear contracts)

Please read more about it in [PHILOSOPHY.md](PHILOSOPHY.md).

License
-------

[](#license)

MIT License. Free to use, modify, and distribute.

Contributing
------------

[](#contributing)

See how to contribute in [CONTRIBUTING.md](CONTRIBUTING.md).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance73

Regular maintenance activity

Popularity7

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~3 days

Total

6

Last Release

151d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b1815540bc9ab8012b61aa12e1a35025d9a0b11a1642977192fd173b6bfc5aa?d=identicon)[esdras-schonevald](/maintainers/esdras-schonevald)

---

Top Contributors

[![esdrasprogramer](https://avatars.githubusercontent.com/u/93490691?v=4)](https://github.com/esdrasprogramer "esdrasprogramer (3 commits)")[![esdras-schonevald](https://avatars.githubusercontent.com/u/64711203?v=4)](https://github.com/esdras-schonevald "esdras-schonevald (3 commits)")[![wallaceSF](https://avatars.githubusercontent.com/u/7256223?v=4)](https://github.com/wallaceSF "wallaceSF (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phprise-data-transfer-object/health.svg)

```
[![Health](https://phpackages.com/badges/phprise-data-transfer-object/health.svg)](https://phpackages.com/packages/phprise-data-transfer-object)
```

###  Alternatives

[akeneo/pim-community-dev

Akeneo PIM, the future of catalog management is open!

1.0k620.8k86](/packages/akeneo-pim-community-dev)[commerceguys/tax

Tax library with a flexible data model, predefined tax rates, powerful resolving logic.

284775.0k](/packages/commerceguys-tax)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[bartlett/php-compatinfo

Find out the minimum version and the extensions required for a piece of code to run

379100.2k7](/packages/bartlett-php-compatinfo)[sylius/promotion

Flexible promotion management for PHP applications.

28495.4k13](/packages/sylius-promotion)[api-platform/doctrine-common

Common files used by api-platform/doctrine-orm and api-platform/doctrine-odm

243.9M41](/packages/api-platform-doctrine-common)

PHPackages © 2026

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