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

ActiveLibrary

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

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

v1.1.3(1mo ago)017↓100%MITPHP

Since Jan 7Pushed 1mo 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 today

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

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

37

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

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

58d 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

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k280.5M5.6k](/packages/doctrine-orm)[gedmo/doctrine-extensions

Doctrine behavioral extensions

4.1k116.9M335](/packages/gedmo-doctrine-extensions)[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k15.1M837](/packages/phpro-grumphp)[sonata-project/admin-bundle

The missing Symfony Admin Generator

2.1k18.7M279](/packages/sonata-project-admin-bundle)[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.2M35](/packages/simshaun-recurr)[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k22.8M271](/packages/doctrine-mongodb-odm)

PHPackages © 2026

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