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

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

kumuwai/data-transfer-object
============================

Load/view dto elements with object, array, json, or dot-notation

v0.0.4(11y ago)52.4k11MITPHP

Since Mar 5Pushed 11y ago2 watchersCompare

[ Source](https://github.com/kumuwai/data-transfer-object)[ Packagist](https://packagist.org/packages/kumuwai/data-transfer-object)[ Docs](https://github.com/kumuwai/data-transfer-object)[ RSS](/packages/kumuwai-data-transfer-object/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (1)

DataTransferObject
==================

[](#datatransferobject)

[![Latest Stable Version](https://camo.githubusercontent.com/ee4ace9af9640966993f934947512d68323cefeef7b2ad2236a48cc8ae6e1c65/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b756d757761692f646174612d7472616e736665722d6f626a6563742e737667)](https://packagist.org/packages/kumuwai/data-transfer-object)[![Build Status](https://camo.githubusercontent.com/73332eadab7d7f8c6298540b9697e224b00adaf6d099c485ad1928f227938f4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b756d757761692f646174612d7472616e736665722d6f626a6563742f6d61737465722e737667)](https://travis-ci.org/kumuwai/data-transfer-object)[![Coverage Status](https://camo.githubusercontent.com/e5a24e9216af3b43128a9adba87a5b7d8b27e5424fcd9047699a49f6c45a9f38/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b756d757761692f646174612d7472616e736665722d6f626a6563742f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/kumuwai/data-transfer-object)[![Quality Score](https://camo.githubusercontent.com/00405ed0a81fe149aa1d458533ba31fba8054b2b812e884e54dd9764fffb47f0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6b756d757761692f646174612d7472616e736665722d6f626a6563742e737667)](https://scrutinizer-ci.com/g/kumuwai/data-transfer-object)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)

This class is designed to make it easy to add and view data. Load objects, arrays, or json; read with object, array, or dot notation; output to json string.

Usage
-----

[](#usage)

You can instantiate the class with an array, arrayable object, or json string. These are all equivalent:

```
$object = new StdObject;
$object->foo = 'bar';

$dto = new DTO($object);
$dto = new DTO(['foo'=>'bar']);
$dto = new DTO('{"foo":"bar"}');

$dto = DTO::make($object);
$dto = DTO::make(['foo'=>'bar']);
$dto = DTO::make('{"foo":"bar"}');
```

Read data with array, object, or dot notation:

```
echo $dto['x'];
echo $dto->x;
echo $dto->get('x');
```

These will also handle nested sets:

```
echo $dto['x']['y']['z'];
echo $dto->x->y->z;
echo $dto->get('x.y.z');
```

By default, an empty string will be returned if a missing property is accessed. Other possibilities:

```
$dto = new DTO([], 'x');            // instantiate with a given default
$dto->setDefault('x');              // change the default
$dto->get('path.to.key', 'x');      // override default for this method call
$dto->setDefault(Null);             // throw an UndefinedProperty exception
```

Add new data with array or object notation:

```
$dto['x'] = 'y';
$dto->x = 'y';
```

Count and iterate the properties:

```
$dto = new DTO([...])
$count = count($dto);
foreach($dto as $key=>$value)
    // do something
```

Laravel Support
---------------

[](#laravel-support)

There are two versions of the data transfer object that implement Laravel-specific interfaces. Use one of these classes if you want Laravel to work with DTOs as first-class Laravel objects.

- Laravel4DTO implements JsonableInterface and ArrayableInterface
- Laravel5DTO implements Jsonable and Arrayable

You can use these to sanitize output before you send it to a view, eg:

```
$models = Model::all();
$output = [];
foreach($models as $model)
    $output[] = new Laravel4DTO([
        'name' => $model->name,
        'paid' => $model->payments->sum('payment_amount'),
        ...
    ]);
return new Collection($output);
```

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

[](#installation)

Install the package via Composer. Edit your composer.json file as follows:

```
"require": {
    "kumuwai/data-transfer-object": "dev-master"
}

```

Next, update Composer from the terminal:

```
composer update

```

TODO
----

[](#todo)

None at this time

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.6% 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

Every ~17 days

Total

3

Last Release

4048d ago

### Community

Maintainers

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

---

Top Contributors

[![jijoel](https://avatars.githubusercontent.com/u/3487641?v=4)](https://github.com/jijoel "jijoel (5 commits)")[![kumuwai](https://avatars.githubusercontent.com/u/11084659?v=4)](https://github.com/kumuwai "kumuwai (4 commits)")

---

Tags

jsonarraydotdto

### Embed Badge

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

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)[selective/transformer

A strictly typed array transformer with dot-access, fluent interface and filters.

3817.8k1](/packages/selective-transformer)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)

PHPackages © 2026

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