PHPackages                             phpgt/dataobject - 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. phpgt/dataobject

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

phpgt/dataobject
================

 Structured, type-safe, immutable data transfer.

v1.1.0(1y ago)010.2k↑42.3%[3 PRs](https://github.com/PhpGt/DataObject/pulls)1MITPHPPHP &gt;=8.1CI passing

Since Jan 17Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/DataObject)[ Packagist](https://packagist.org/packages/phpgt/dataobject)[ GitHub Sponsors](https://github.com/phpgt)[ RSS](/packages/phpgt-dataobject/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (18)Used By (1)

Structured, type-safe, immutable data transfer.
===============================================

[](#structured-type-safe-immutable-data-transfer)

A Data Transfer Objects (DTO) in a programming language is a design pattern that facilitates transfer of data between different layers of an application. This library introduces the `DataObject` class which can be built from an existing associative array or standard object, using the `DataObjectBuilder` class.

---

[ ![Build status](https://camo.githubusercontent.com/91307b3bc70b7e9a451423611387d644e5f5edf1d9185ec2f0ada22da7cc84cc/68747470733a2f2f62616467652e7374617475732e7068702e67742f646174616f626a6563742d6275696c642e737667)](https://giub.com/PhpGt/DataObject/actions)[ ![Code quality](https://camo.githubusercontent.com/a35b24b8cb39aad92d1d3cd053892f7399251b7a90fedeb493683c92b8fd31b8/68747470733a2f2f62616467652e7374617475732e7068702e67742f646174616f626a6563742d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/DataObject)[ ![Code coverage](https://camo.githubusercontent.com/88e0ef72939d02c8bb9056622d4839a02ceb4851ddacb59d381e36c0ee8d20db/68747470733a2f2f62616467652e7374617475732e7068702e67742f646174616f626a6563742d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/DataObject)[ ![Current version](https://camo.githubusercontent.com/bc2bc68c43398c4d83b2f71fda8dbf25fc571d5dbacde91bd310a35b6f29fd14/68747470733a2f2f62616467652e7374617475732e7068702e67742f646174616f626a6563742d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/DataObject)[ ![PHP.Gt/DataObject documentation](https://camo.githubusercontent.com/69713fec2f82ee0852a53e1036d1ff32554ff16b75eccb07cbd0a17d1d2451cc/68747470733a2f2f62616467652e7374617475732e7068702e67742f646174616f626a6563742d646f63732e737667)](http://www.php.gt/dataobject)A `DataObject` has the following features:

- It is **immutable**, meaning that code can't modify the data it represents
- It provides **type-safe** getters to the contained data
- It can be **nested** within other `DataObject`s
- It can be converted to and from associative arrays and standard objects

Usage example
-------------

[](#usage-example)

Load an object into a `DataObject`, then pass to a third party library for processing.

Due to the immutability of the `DataObject` class, there is no risk of the third party library making changes to the contents of the data.

```
use Gt\DataObject\DataObjectBuilder;

// Create a new Builder and build the DataObject from an associative array.
// For example, data loaded from another remote data source.
$sourceData = [
	"id" => 105,
	"name" => "Edgar Scolmore",
	"address" => [
		"street" => "32 Trestles Lane",
		"town" => "Lensworth",
		"county" => "Scamperingshire",
		"postcode" => "SC41 8PN"
	],
];
$builder = new DataObjectBuilder();
$data = $builder->fromAssociativeArray($sourceData);

// Pass the data to a third party to process it.
ThirdParty::processData($data);

// Now we can use the data ourselves for whatever purpose:
Database::store(
	id: $data->getInt("id"),
	refname: $data->getString("name"),
);
```

Working with JSON data
----------------------

[](#working-with-json-data)

A JSON data structure is almost identical in scope to the DataObject introduced in this repository, with one key difference: JSON data can represent a primitive data type, not always key-value-pairs. Because of this, [PHP.Gt/Json is maintained separately to provide structured, type-safe, immutable JSON objects](https://php.gt/json) as an extension to this DataObject repository.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance55

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~124 days

Recently: every ~221 days

Total

13

Last Release

458d ago

Major Versions

v0.4.0 → v1.0.02021-03-15

PHP version history (2 changes)v0.1.0PHP &gt;=8.0

v1.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (1 commits)")

---

Tags

data-transfer-objectdtodto-patternimmutableimmutable-datastructurestype-safety

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-dataobject/health.svg)

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

###  Alternatives

[felixnagel/t3extblog

A record based blog extension for TYPO3 CMS. Easy to use and packed with features (incl. comments, subscriptions for comments and posts, Wordpress like subscription manager, reasonable email sending in FE and BE, GDPR ready, BE modules, Dashboard widgets, RSS, Sitemap, ...). Flexible and powerful!

3421.6k](/packages/felixnagel-t3extblog)

PHPackages © 2026

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