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(3mo ago)017↓100%5MITPHP

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

37

—

LowBetter than 82% of packages

Maintenance86

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community15

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

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

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[liuggio/fastest

Simple parallel testing execution... with some goodies for functional tests.

4825.6M26](/packages/liuggio-fastest)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[doctrine/phpcr-odm

PHP Doctrine Content Repository Object Document Mapper (ODM) provides transparent persistence for PHP objects.

1811.5M97](/packages/doctrine-phpcr-odm)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)

PHPackages © 2026

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