PHPackages                             bentools/doctrine-changeset - 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. [Database &amp; ORM](/categories/database)
4. /
5. bentools/doctrine-changeset

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

bentools/doctrine-changeset
===========================

Doctrine UnitOfWork helpers to access changesets in an easy way.

1.1(2y ago)0433MITPHPPHP &gt;=8.2

Since Oct 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/bpolaszek/doctrine-changeset)[ Packagist](https://packagist.org/packages/bentools/doctrine-changeset)[ RSS](/packages/bentools-doctrine-changeset/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (17)Versions (3)Used By (0)

[![CI Workflow](https://github.com/bpolaszek/doctrine-changeset/actions/workflows/ci.yml/badge.svg)](https://github.com/bpolaszek/doctrine-changeset/actions/workflows/ci.yml)[![Coverage](https://camo.githubusercontent.com/d2412dd4512a75c567cb9fd034564329ec3361823dde563ebf66882fec998e68/68747470733a2f2f636f6465636f762e696f2f67682f62706f6c61737a656b2f646f637472696e652d6368616e67657365742f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4c35756c5461796d6274)](https://codecov.io/gh/bpolaszek/doctrine-changeset)

Doctrine Changes Tracker
========================

[](#doctrine-changes-tracker)

This package provides an `EntityTracker` service for your Doctrine entities. This service allows you to easily track changes made to an entity, i.e.

```
$entity->name = 'foo';
$tracker->hasChanged($entity); // true
$tracker->hasChanged($entity, 'name'); // true

$changeSet=$tracker->getChangeSet($entity, 'name');
$changeSet->from; // Previous value
$changeSet->to; // New value
$changeSet->hadPreviousValue('foo'); // false
$changeSet->hasNewValue('bar'); // false
$changeSet->hasChangedFor(null, 'foo'); // true
$changeSet->hadPreviousValue(whatever()->except(null)); // false
$changeSet->hasNewValue(oneOf('foo', 'bar')); // true
```

This package also provides a `#[TrackChanges]` attributes on properties typed as `object` - this allows Doctrine to be aware on changes on nested objects (which isn't the case by default, unless you assign a different object).

Usage
-----

[](#usage)

Just inject `EntityTracker` in your services and use the helper methods.

### Example:

[](#example)

```
