PHPackages                             maplephp/dto - 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. maplephp/dto

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

maplephp/dto
============

DTO library in PHP provides benefits such as encapsulating data, enforcing immutability and facilitating data transformation.

v3.1.0(5mo ago)456719Apache-2.0PHPPHP &gt;=8.2CI passing

Since Nov 29Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/DTO)[ Packagist](https://packagist.org/packages/maplephp/dto)[ Docs](https://maplephp.github.io/DTO/)[ RSS](/packages/maplephp-dto/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (9)

Darn Tidy Object (DTO)
======================

[](#darn-tidy-object-dto)

DTO stands for **Darn Tidy Object**, a playful twist on the traditional Data Transfer Object. But this isn’t your average DTO. It’s a fully-loaded toolkit for **traversing, transforming, and tidying up structured data** in PHP with style, power, and simplicity.

*It also makes your life easier by ensuring every piece of data is returned in the correct type-helping. Whether you expect an int, string, bool, or even a callable, DTO gives you strict, reliable access to your data with minimal effort.*

---

📦 Installation
--------------

[](#-installation)

```
composer require maplephp/dto
```

📘 Documentation
---------------

[](#-documentation)

- [Why DTO?](https://maplephp.github.io/dto/docs/intro#why-dto)
- [Traverse Collection](https://maplephp.github.io/dto/docs/traverse)
- [Format string](https://maplephp.github.io/dto/docs/format-string)
- [Format Number](https://maplephp.github.io/dto/docs/format-number)
- [Format Clock](https://maplephp.github.io/dto/docs/format-clock)
- [Format Dom](https://maplephp.github.io/dto/docs/format-dom)

---

How It Works
------------

[](#how-it-works)

DTO wraps your data arrays into a powerful, fluent object structure. Instead of cluttered array access, your code becomes expressive and self-documenting.

### Before DTO

[](#before-dto)

```
$name = isset($data['user']['profile']['name'])
    ? ucfirst(strip_tags($data['user']['profile']['name']))
    : 'Guest';
```

### With DTO

[](#with-dto)

```
$name = $obj->user->profile->name
    ->strStripTags()
    ->strUcFirst()
    ->fallback('Guest')
    ->get();
```

Much tidier, right?

---

✨ Core Features
---------------

[](#-core-features)

### Smart Data Traversal

[](#smart-data-traversal)

Access deeply nested data without ever worrying about undefined keys.

```
echo $obj->article->tagline->strToUpper();
// Result: 'HELLO WORLD'

echo $obj->article->content->strExcerpt()->strUcFirst();
// Result: 'Lorem ipsum dolor sit amet...'
```

---

### Correct Type Handling (with ease)

[](#correct-type-handling-with-ease)

No more clunky `is_numeric` checks or `intval` casts. DTO makes it simple to extract values in the exact type you expect:

```
$orderId = $dto->order->id->toInt();
// Result: 1234 (int)
```

Handle flexible types cleanly with fallbacks:

```
$callback = $dto->settings->onReady->acceptType(['callable', 'null']);
if (is_callable($callback)) {
    $callback(); // Result: Runs a startup hook or closure
}
```

---

### Built-In Data Transformation

[](#built-in-data-transformation)

Transform values directly using built-in helpers like:

#### Strings (`str`)

[](#strings-str)

```
echo $obj->title->strSlug();
// Result: 'my-awesome-title'
```

#### Numbers (`num`)

[](#numbers-num)

```
echo $obj->filesize->numToFilesize();
// Result: '1.95 kb'

echo $obj->price->numRound(2)->numToCurrency("USD");
// Result: $1,999.99
```

#### Dates (`clock`)

[](#dates-clock)

```
echo $obj->created_at->clockFormat('d M, Y', 'sv_SE');
// Result: '21 augusti 2025'

echo $obj->created_at->clockIsToday();
// Result: true
```

#### HTML DOM Builder (`dom`)

[](#html-dom-builder-dom)

```
echo $obj->heading->domTag("h1.title");
// Result: My Heading
```

Or nest elements with ease:

```
echo $obj->title->domTag("h1.title")->domTag("header");
// Result: Hello
```

---

### Built-In Collection Support

[](#built-in-collection-support)

Work with arrays of objects just as cleanly:

```
foreach ($obj->users->fetch() as $user) {
    echo $user->firstName->strUcFirst();
}
```

---

### Modify Data on the Fly

[](#modify-data-on-the-fly)

Change values directly without verbose conditionals:

```
$updated = $obj->shoppingList->replace([0 => 'Shampoo']);
print_r($updated->toArray());
```

---

Now go forth, write cleaner code, and let DTO handle the messy parts.

---

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance77

Regular maintenance activity

Popularity20

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 95.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 ~110 days

Recently: every ~183 days

Total

8

Last Release

163d ago

Major Versions

v1.2.1 → v2.0.02024-10-02

v2.0.0 → v3.0.02025-03-25

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v3.1.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (43 commits)")[![CreativeWaDev](https://avatars.githubusercontent.com/u/153771800?v=4)](https://github.com/CreativeWaDev "CreativeWaDev (2 commits)")

---

Tags

arraycollectiondata-objectdata-transfer-objectdatedomdtoformatformatterhtmlimmutablenumberphpstringtransformtravsersutilityarraystringutilitydomdatecollectiontransformdata-transfer-objectdtoimmutablenumberdata objectdarn-tidy-objecttravsers

### Embed Badge

![Health badge](/badges/maplephp-dto/health.svg)

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

###  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.1k417.9M1.7k](/packages/nette-utils)[graze/sort

A collection of array sorting transforms and functions

11295.5k2](/packages/graze-sort)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2518.6k](/packages/iteks-laravel-enum)

PHPackages © 2026

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