PHPackages                             adaddinsane/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. [File &amp; Storage](/categories/file-storage)
4. /
5. adaddinsane/dataobject

ActiveLibrary[File &amp; Storage](/categories/file-storage)

adaddinsane/dataobject
======================

Data object storage and recovery with sorting, filtering and merging

1.1.0(1y ago)15.5kMITPHPPHP &gt;=8.1

Since Oct 1Pushed 1y ago1 watchersCompare

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

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

Data Object
===========

[](#data-object)

This package provides two extendable classes for accessing the contents of a data array through various default and custom methods.

Why would you do this? The main reason is that simply passing arrays gives you no validation of *what* is being passed, but an array as an object can be type-hinted so provide better certainty of correct code.

All classes are abstract (which is ignored in the examples below) and must be extended in order to be used.

Options
-------

[](#options)

One class allows the data to be written, while the other provides an immutable object which has no `set()` method.

```
$data = [
  'a' => 'A',
  'b' => 'B'
];

$object = new DataObject($data);

$a = $object->get('a');
$b = $object->get('b', 'z'); // Default value 'z', if 'b' key is not set.

$data->set('b', 'q');

$immutable = new ImmutableDataObject($data);

$immutable->set('b', 'q'); // Method not permitted.
```

This package can be used in conjunction with the ParamVerify package that can check the contents of an array before creating the data object.

How to use
----------

[](#how-to-use)

You could just use these classes as they stand but that's not the best way.

Let's say you fetch data from an API in the form of an array, we'll call it personData. To use the DataObject with that you'd create a new class:

```
class PersonData extends \Adaddinsane\DataObject\ImmutableDataObject {

    public function getFullName(): string {
        return $this->get('given_name') . ' ' . $this->get('family_name');
    }
}
```

You can create methods to extract precisely the data you need.

And if the API data structure changes, you just change the class to match. If you use `getFullName()` in multiple places, you only need to change it once.

You can now type-hint in arguments to ensure you're delivering the right item.

```
function analyse(PersonData $person) { ... }
```

GenericBag
----------

[](#genericbag)

This is a third abstract object which extends a DataObject to allow the items being added to be verified as being of a specific class type or types.

The verification function can also be overridden if something other than classes are being stored.

The point of a Bag is that you can have a collection of items which can be passed around together, and can be type-hinted to ensure the right items are being delivered.

### Merge

[](#merge)

In your GenericBag class, implement the `GenericBagMergeInterface` class and `trait GenericBagMergeTrait;` you then have access to a merge() method which takes another GenericBag object as a parameter.

### Filter

[](#filter)

In your GenericBag class, implement the `GenericBagFilterInterface` class and `trait GenericBagFilterTrait;` you then have access to a filter() method which takes a filter callable.

The filter callable is used in an `array_filter()` command on the GenericBag's data to extract a subset of items which is then used to create and return a new GenericBag of the same class.

### Sort

[](#sort)

In your GenericBag class, implement the `GenericBagSortInterface` class and `trait GenericBagSortTrait;` you then have access to a sort() method which takes a sort callable.

The sort callable is used in an `uasort()` command on the GenericBag's data which sorts the items of this GenericBag. No value is returned.

Other forms of access
---------------------

[](#other-forms-of-access)

The DataObjects also implement the ArrayIterator and Count interfaces, which means that if you want to you can use the object in a loop or count the values.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Total

5

Last Release

640d ago

Major Versions

0.2.1-alpha → 1.0.02023-11-30

PHP version history (2 changes)0.1.0-alphaPHP &gt;=7.2

1.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/291255?v=4)[Steve Turnbull](/maintainers/adaddinsane)[@adaddinsane](https://github.com/adaddinsane)

---

Top Contributors

[![adaddinsane](https://avatars.githubusercontent.com/u/291255?v=4)](https://github.com/adaddinsane "adaddinsane (10 commits)")

---

Tags

arraydataobjectfilterstoragesortmergevaluesimmutable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[samsonasik/array-lookup

A fast lookup library that help you verify and search array and Traversable data

2868.2k2](/packages/samsonasik-array-lookup)[graze/data-structure

Data collections and containers

12295.9k10](/packages/graze-data-structure)

PHPackages © 2026

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