PHPackages                             sahanh/simpledto - 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. sahanh/simpledto

ActiveLibrary

sahanh/simpledto
================

Simple DTO object to move data

1.2.1(11y ago)37.4kMITPHPPHP &gt;=5.4.0

Since Aug 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/sahanh/SimpleDTO)[ Packagist](https://packagist.org/packages/sahanh/simpledto)[ RSS](/packages/sahanh-simpledto/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

SimpleDTO
=========

[](#simpledto)

Simple DTO object to move data. Requires PHP 5.4

\###Practical Usage When returning complex data, instead of returning an array DTOs can be returned.

```
class UserService
{
    public function getUsers()
    {
        $rows = $this->db->users->get();
        return DTO::make($rows);
    }
}

```

View or Controllers can use DTO objects to access data. No need to worry about undefined index errors when using get method.

```
{{ $data->get('name') }}

@foreach($data->get('cars') as $car)
    {{ $car }}
@endforeach

```

\###Installing Package can be installed via composer.

\###Install Composer curl -sS  | php

```
Next, update your project's composer.json file to include EZCash:

{
    "require": {
        "sahanh/simpledto": "~1.0"
    }
}

```

\###Making DTO Object use SH\\SimpleDTO\\DTO;

```
$raw = [
    'id'      => 1,
    'name'    => 'John Doe',
    'email'   => 'john@doe.com',
    'address' => [
        'street' => '123 Main St.',
        'city'   => 'Wind'
    ],
    'cars'  => [
        'BMW-7',
        'Toyota Supra',
        'Nissan GT',
        'Jaguar'
    ]
];

//pass an array or stdClass objects
$dto = DTO::make($raw);

```

\###Accessing Data //accessing properties echo $dto-&gt;name; //John Doe echo $dto-&gt;address-&gt;city; //Wind

```
//accessing as an array
echo $dto['name']; //John Doe
echo $dto["address"]["city"] //Wind

```

\####Using dot-notation DTO's data can be accessed using get method, get method accept `.` for nested elements

```
echo $dto->get('address.city');

```

One advantage of get is, data can be accessed without making sure if they exist or not.

```
//returns NULL without errors, (no undefined index errors like in arrays)
$dto->get('address.country');

```

\###Iterating For every nested array element data new DTO object will be created on retrival, and DTO object implements `IteratorAggregate` inteface.

```
foreach ($dto->cars as $car) {
    echo $car;
}

//since `$dto->cars` is an array, `$dto->cars` will be returning another DTO object.
$cars = $dto->cars;
echo $cars->get(0); //accessing get() of DTO object

```

\###JSON Serializing Pass the DTO object to json\_encode and get the data in json

```
echo json_encode($dto);

```

\###Write Protected Data inside a DTO object cannot be modified once created making it perfect to move around.

```
//RuntimeException - 'Data cannot be modified'
$dto->new_value   = 'Some value';
$dto['new_value'] = 'Some value';

```

---

Credits: The library uses illuminate/helpers package

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

4043d ago

PHP version history (2 changes)1.0PHP 5.4.\*

1.1.2PHP &gt;=5.4.0

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/sahanh-simpledto/health.svg)

```
[![Health](https://phpackages.com/badges/sahanh-simpledto/health.svg)](https://phpackages.com/packages/sahanh-simpledto)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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