PHPackages                             andrey-helldar/simple-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. andrey-helldar/simple-data-transfer-object

Abandoned → [dragon-code/simple-data-transfer-object](/?search=dragon-code%2Fsimple-data-transfer-object)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

andrey-helldar/simple-data-transfer-object
==========================================

Simple Data Transfer Objects

2.8.0(2y ago)85.1k2MITPHPPHP ^7.3 || ^8.0CI passing

Since Jul 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/TheDragonCode/simple-data-transfer-object)[ Packagist](https://packagist.org/packages/andrey-helldar/simple-data-transfer-object)[ Fund](https://boosty.to/dragon-code)[ Fund](https://www.donationalerts.com/r/dragon_code)[ RSS](/packages/andrey-helldar-simple-data-transfer-object/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (20)Used By (0)

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

[](#simple-data-transfer-object)

[![Simple DTO](https://camo.githubusercontent.com/6325dfd3fe1220959c330d291e924df8cf9f468ff502860c4a9d7ea5344ac1ab/68747470733a2f2f707265766965772e647261676f6e2d636f64652e70726f2f546865447261676f6e436f64652f73696d706c652d64746f2e7376673f6272616e643d706870)](https://camo.githubusercontent.com/6325dfd3fe1220959c330d291e924df8cf9f468ff502860c4a9d7ea5344ac1ab/68747470733a2f2f707265766965772e647261676f6e2d636f64652e70726f2f546865447261676f6e436f64652f73696d706c652d64746f2e7376673f6272616e643d706870)

[![Stable Version](https://camo.githubusercontent.com/df1b679da54d8d861bc7a7491d47f3546144e8b99d0420f6df308e6a678f3a12/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f546865447261676f6e436f64652f73696d706c652d646174612d7472616e736665722d6f626a6563743f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/simple-dto)[![Unstable Version](https://camo.githubusercontent.com/85afbac0745eb275d863cee4b1701a70c0e30315d27990b00f1abd553b8761e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d6d61696e2d6f72616e67653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/simple-dto)[![Total Downloads](https://camo.githubusercontent.com/d2a73e950746eb9943f790b69e5c51e5f273e15b9e11e486b5f707bab8df0043/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647261676f6e2d636f64652f73696d706c652d64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/simple-dto)[![License](https://camo.githubusercontent.com/30d29161b9ea3617726575f8b24420cf95995c2a2cf952f4af230393c585a615/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f647261676f6e2d636f64652f73696d706c652d64746f2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Tip

Use the [`spatie/laravel-data`](https://github.com/spatie/laravel-data) instead.

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

[](#installation)

To get the latest version of `Simple Data Transfer Object`, simply require the project using [Composer](https://getcomposer.org):

```
composer require dragon-code/simple-dto
```

Or manually update `require` block of `composer.json` and run `composer update`.

```
{
    "require": {
        "dragon-code/simple-dto": "^2.0"
    }
}
```

### Upgrade from `andrey-helldar/simple-data-transfer-object`

[](#upgrade-from-andrey-helldarsimple-data-transfer-object)

1. Replace `"andrey-helldar/simple-data-transfer-object": "^1.0"` with `"dragon-code/simple-dto": "^2.0"` in the `composer.json` file;
2. Replace `Helldar\SimpleDataTransferObject` namespace prefix with `DragonCode\SimpleDataTransferObject` in your application;
3. Call the `composer update` console command.

### Upgrade from `dragon-code/simple-data-transfer-object`

[](#upgrade-from-dragon-codesimple-data-transfer-object)

1. Replace `dragon-code/simple-data-transfer-object` with `dragon-code/simple-dto` in the `composer.json` file;
2. Call the `composer update` console command.

Using
-----

[](#using)

### Basic

[](#basic)

```
namespace App\DTO;

use DragonCode\SimpleDataTransferObject\DataTransferObject;

class YourInstance extends DataTransferObject
{
    public $foo;

    public $bar;

    public $baz;

    public $qwerty;
}

$instance = YourInstance::make([
    'foo' => 'Foo',
    'bar' => 'Bar',
    'baz' => 'Baz'
]);

return $instance->foo;
// Foo

return $instance->bar;
// Bar

return $instance->baz;
// Baz

return $instance->qwerty;
// null
```

### Mappings

[](#mappings)

```
namespace App\DTO;

use DragonCode\SimpleDataTransferObject\DataTransferObject;

class YourInstance extends DataTransferObject
{
    public $foo;

    public $bar;

    public $baz;

    public $qwerty;

    protected $map = [
        'data.foo' => 'foo',
        'data.bar' => 'bar',
    ];
}

$instance = YourInstance::make([
    'data' => [
        'foo' => 'Foo',
        'bar' => 'Bar'
    ],
    'baz' => 'Baz'
]);

return $instance->foo;
// Foo

return $instance->bar;
// Bar

return $instance->baz;
// Baz

return $instance->qwerty;
// null
```

### Casts

[](#casts)

```
namespace App\DTO;

use DragonCode\SimpleDataTransferObject\DataTransferObject;
use DragonCode\Support\Facades\Helpers\Str;

class YourInstance extends DataTransferObject
{
    public $foo;

    public $bar;

    public $baz;

    public $qwerty;

    protected $map = [
        'data.foo' => 'foo',
        'data.bar' => 'bar',
    ];

    protected function castFoo($value)
    {
        return Str::upper($value);
    }
}

$instance = YourInstance::make([
    'data' => [
        'foo' => 'Foo',
        'bar' => 'Bar'
    ],
    'baz' => 'Baz'
]);

return $instance->foo;
// FOO

return $instance->bar;
// Bar

return $instance->baz;
// Baz

return $instance->qwerty;
// null
```

### Nested Objects

[](#nested-objects)

With the help of casts, you can also easily create nested objects:

```
use Tests\Fixtures\Nested\Company;

$company = Company::make([
    'title' => 'First Company',

    'projects' => [
        [
            'title'  => 'Project 1',
            'domain' => 'https://example.com',

            'developers' => [
                [
                    'name'  => 'Andrey Helldar',
                    'email' => 'helldar@ai-rus.com',
                ],
                [
                    'name'  => 'John Doe',
                    'email' => 'doe@example.com',
                ],
            ],
        ],
    ],
]);

$company->title;
// First Company

foreach ($company->projects as $project) {
    $project->title;
    // 0: Project 1

    foreach ($project->developers as $developer) {
        $developer->name;
        // 0: Andrey Helldar
        // 1: John Doe
    }
}
```

For example, casting test company object:

```
namespace Tests\Fixtures\Nested;

use DragonCode\SimpleDataTransferObject\DataTransferObject;

class Company extends DataTransferObject
{
    public string $title;

    /** @var \Tests\Fixtures\Nested\Project[] */
    public array $projects;

    protected function castProjects(array $projects): array
    {
        return array_map(static function (array $project) {
            return Project::make($project);
        }, $projects);
    }
}
```

### From

[](#from)

#### Array

[](#array)

```
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\Simple;

class Foo
{
    protected array $items = [
        'foo' => 'Foo',
        'bar' => 'Bar',
    ];

    protected function dto(): DataTransferObject
    {
        return Simple::fromArray($this->items);
    }
}
```

#### Json

[](#json)

```
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\Simple;

class Foo
{
    protected string $json = '{"foo":"Foo","bar":"Bar"}';

    protected function dto(): DataTransferObject
    {
        return Simple::fromJson($this->json);
    }
}
```

#### Object

[](#object)

```
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\CustomObject;
use Tests\Fixtures\Simple;

class Foo
{
    protected CustomObject $object;

    protected function dto(): DataTransferObject
    {
        return Simple::fromObject($this->object);
    }
}
```

#### Request

[](#request)

```
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Symfony\Component\HttpFoundation\Request;
use Tests\Fixtures\Simple;

class Foo
{
    protected Request $request;

    protected function dto(): DataTransferObject
    {
        return Simple::fromRequest($this->request)
    }
}
```

### Get And Set

[](#get-and-set)

You can use the `get` and `set` methods in your app:

```
namespace App\DTO;

use DragonCode\SimpleDataTransferObject\DataTransferObject;

class YourInstance extends DataTransferObject
{
    public $foo;
}

$instance = YourInstance::make([
    'foo' => 'none',
]);

return $instance->foo;
// none

return $instance->get('foo');
// none

$instance->set('foo', 'Foo');

return $instance->foo;
// Foo
```

Helpers
-------

[](#helpers)

For your convenience, starting from version [2.17](https://github.com/TheDragonCode/contracts/releases/tag/v2.17.0) of the [`dragon-code/contracts`](https://github.com/TheDragonCode/contracts/releases/tag/v2.17.0) package, we have added a new interface that declares the implementation of the public `dto` method. This way you can better control your application to return DTO objects.

Of course, don't forget to implement the interface 😉

For example:

```
namespace App\Http\Requests\Companies;

use App\Objects\Company;
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use DragonCode\Contracts\DataTransferObject\Dtoable;

class CreateRequest implements Dtoable
{
    // ...

    public function dto(): DataTransferObject
    {
        return Company::fromRequest($this);
    }
}

// Other place
public function store(CreateRequest $request)
{
    $name = $request->dto()->name;
}
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~120 days

Total

19

Last Release

794d ago

Major Versions

1.x-dev → v2.0.02021-11-11

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

v2.1.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b77790e612f1c9beed1e1533e36eba4954fbd6da2a5c9f71e845cd0f5465f0ad?d=identicon)[Helldar](/maintainers/Helldar)

---

Top Contributors

[![andrey-helldar](https://avatars.githubusercontent.com/u/10347617?v=4)](https://github.com/andrey-helldar "andrey-helldar (46 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (33 commits)")[![akbarali1](https://avatars.githubusercontent.com/u/39323182?v=4)](https://github.com/akbarali1 "akbarali1 (1 commits)")[![ekadesh](https://avatars.githubusercontent.com/u/122966905?v=4)](https://github.com/ekadesh "ekadesh (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

data-transfer-objectdtodragondragon codeandrey helldar

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[dragon-code/pretty-array

Simple conversion of an array to a pretty view

177.6M4](/packages/dragon-code-pretty-array)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)

PHPackages © 2026

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