PHPackages                             stratadox/entity-state - 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. stratadox/entity-state

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

stratadox/entity-state
======================

v0.1(6y ago)06MITPHPPHP &gt;=7.2

Since Jul 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Stratadox/EntityState)[ Packagist](https://packagist.org/packages/stratadox/entity-state)[ RSS](/packages/stratadox-entity-state/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

Entity State
============

[](#entity-state)

[![Build Status](https://camo.githubusercontent.com/7b69544164f06100638ab34bd0eb07e8f5b6914d5a753af1dd5bb4b99e0bae4e/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f456e7469747953746174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/EntityState)[![Coverage Status](https://camo.githubusercontent.com/f36eb097ab79502765c36fcf2c32f2fda222656af845c7d2d2953e102b5b50e9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f456e7469747953746174652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/EntityState?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/38041954b30b158c13650ef6d0647f6be34472ff6c84bb59cf3d5545fee8fafc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f456e7469747953746174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/EntityState/?branch=master)[![Infection Minimum](https://camo.githubusercontent.com/894bc806dfe9c46d1e3f69dae5bffb78611a7009601c6ba70299155572720ade/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d73692d39352d627269676874677265656e2e737667)](https://travis-ci.org/Stratadox/EntityState)[![PhpStan Level](https://camo.githubusercontent.com/7d521d242d198a9468ca6170cc4416765da9273ff094476e7125934666afc7da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d372f372d627269676874677265656e2e737667)](https://travis-ci.org/Stratadox/EntityState)[![Maintainability](https://camo.githubusercontent.com/28fb6d0571b2919b2dc9949da1e1c5ffe9eb484581b598ee1f248f966cdc0b57/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f38633237643632613032386539323936343864322f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Stratadox/EntityState/maintainability)[![Latest Stable Version](https://camo.githubusercontent.com/5d3b638e4019f15b2bf73694cefa70ddccbe37b469b9afc17fcefc4c843243e2/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f656e746974792d73746174652f762f737461626c65)](https://packagist.org/packages/stratadox/entity-state)[![License](https://camo.githubusercontent.com/3481afcfa86a964f81d25346c405d0a460386bf8e5f297dfbcb36eca77dc013d/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f656e746974792d73746174652f6c6963656e7365)](https://packagist.org/packages/stratadox/entity-state)

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

[](#installation)

Install with `composer require stratadox/entity-state`

What is this?
-------------

[](#what-is-this)

This package models the entity state at a certain point in the execution of the business logic.

The model is built in such a way that it can find differences in terms of added, altered or removed entities, when comparing itself to another point in the process.

Additionally, the package comes with a service to extract the state of the entities.

How to use this?
----------------

[](#how-to-use-this)

Step 1: Extract the state of the entities from the [`Identity Map`](https://github.com/Stratadox/IdentityMap).

```
$originalState = Extract::state()->from($identityMap);
```

Step 2: Make some changes in the domain.

```
$identityMap = $identityMap->add('id-26', new Something('foo'));

$identityMap->get(User::class, '1')->changeNameTo('Chuck Norris');

$identityMap = $identityMap->remove(Foo::class, '3');
```

(Note: In real life you'd access the identity map through repositories instead)

Step 3: Extract the new state from the entities in the identity map.

```
$newState = Extract::state()->from($identityMap);
```

Step 4: Get the changes since the original state was captured.

```
$changes = $newState->changesSince($originalState);
```

Step 5: Profit.

```
assert($changes->added()[0]->class() === Something::class);
assert($changes->added()[0]->id() === 'id-26');

assert($changes->altered()[0]->class() === User::class);
assert($changes->altered()[0]->id() === '1');

assert($changes->removed()[0]->class() === Foo::class);
assert($changes->removed()[0]->id() === '3');

assert($changes->altered()[0]->properties()[0]->name() === 'userName');
assert($changes->altered()[0]->properties()[0]->value() === 'Chuck Norris');
```

### Name formatting

[](#name-formatting)

Notice that in the above example, the user's name is stored as a string value in the property `userName`. If instead the `User` class would have a `Name` value object, the assertion would look more like this:

```
assert($changes->altered()[0]->properties()[0]->name() === 'Name:userName.name');
```

If this `Name` object were contained in an array, the result would look like this:

```
assert($changes->altered()[0]->properties()[0]->name() === 'Name:array:userName[0].name');
```

### Value formatting

[](#value-formatting)

It may in some cases be preferable to store the string representation of an instance, rather than all its properties. To extract a string representation of the objects of a class, one can use:

```
$entityState = Extract::stringifying(UuidInterface::class)->from($identityMap);
```

To do
-----

[](#to-do)

Potential to-do's:

- Increase performance by hashing properties names?
- Split names into parts?
- Add methods for querying properties?
- Make properties exportable for hydration

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2491d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5333260?v=4)[Stratadox](/maintainers/Stratadox)[@Stratadox](https://github.com/Stratadox)

---

Top Contributors

[![Stratadox](https://avatars.githubusercontent.com/u/5333260?v=4)](https://github.com/Stratadox "Stratadox (27 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stratadox-entity-state/health.svg)

```
[![Health](https://phpackages.com/badges/stratadox-entity-state/health.svg)](https://phpackages.com/packages/stratadox-entity-state)
```

###  Alternatives

[mediawiki/semantic-glossary

A terminology markup extension with a Semantic MediaWiki back-end

1352.4k](/packages/mediawiki-semantic-glossary)[thanks-to-it/wp-dich

121.1k](/packages/thanks-to-it-wp-dich)

PHPackages © 2026

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