PHPackages                             simplethings/entity-audit - 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. simplethings/entity-audit

ActiveLibrary

simplethings/entity-audit
=========================

Audit for Doctrine Entities

106736[1 PRs](https://github.com/simplethings/entity-audit/pulls)PHP

Since Aug 4Pushed 6y ago3 watchersCompare

[ Source](https://github.com/simplethings/entity-audit)[ Packagist](https://packagist.org/packages/simplethings/entity-audit)[ RSS](/packages/simplethings-entity-audit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EntityAudit Extension for Doctrine2
===================================

[](#entityaudit-extension-for-doctrine2)

[![Build Status](https://camo.githubusercontent.com/65be7479f267b85ddd26e31c069aefeafb05ede82f2ed2e51dd8a17068b83183/68747470733a2f2f7472617669732d63692e6f72672f73696d706c657468696e67732f656e746974792d61756469742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/simplethings/entity-audit)

This extension for Doctrine 2 is inspired by [Hibernate Envers](http://www.jboss.org/envers) and allows full versioning of entities and their associations.

How does it work?
-----------------

[](#how-does-it-work)

There are a bunch of different approaches to auditing or versioning of database tables. This extension creates a mirroring table for each audited entitys table that is suffixed with "\_audit". Besides all the columns of the audited entity there are two additional fields:

- rev - Contains the global revision number generated from a "revisions" table.
- revtype - Contains one of 'INS', 'UPD' or 'DEL' as an information to which type of database operation caused this revision log entry.

The global revision table contains an id, timestamp, username and change comment field.

With this approach it is possible to version an application with its changes to associations at the particular points in time.

This extension hooks into the SchemaTool generation process so that it will automatically create the necessary DDL statements for your audited entities.

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

[](#installation)

\###Installing the lib/bundle

Simply run assuming you have installed composer.phar or composer binary:

```
$ composer require simplethings/entity-audit
```

For standalone usage you have to pass the EntityManager.

```
use Doctrine\ORM\EntityManager;
use SimpleThings\EntityAudit\AuditManager;

$config = new \Doctrine\ORM\Configuration();
// $config ...
$conn = array();
$em = EntityManager::create($conn, $config, $evm);

$auditManager = AuditManager::create($em);
```

Usage
-----

[](#usage)

### Define auditable entities

[](#define-auditable-entities)

You need add `Auditable` annotation for the entities which you want to auditable.

```
use Doctrine\ORM\Mapping as ORM;
use SimpleThings\EntityAudit\Mapping\Annotation as Audit;

/**
 * @ORM\Entity()
 * @Audit\Auditable()
 */
class Page {
 //...
}
```

You can also ignore fields in an specific entity.

```
class Page {

    /**
     * @ORM\Column(type="string")
     * @Audit\Ignore()
     */
    private $ignoreMe;

}
```

### Use AuditReader

[](#use-auditreader)

Querying the auditing information is done using a `SimpleThings\EntityAudit\AuditReader` instance.

You can create the audit reader from the audit manager:

```
$auditReader = $auditManager->createAuditReader();
```

### Find entity state at a particular revision

[](#find-entity-state-at-a-particular-revision)

This command also returns the state of the entity at the given revision, even if the last change to that entity was made in a revision before the given one:

```
$articleAudit = $auditReader->find(
    SimpleThings\EntityAudit\Tests\ArticleAudit::class,
    $id = 1,
    $rev = 10
);
```

Instances created through `AuditReader#find()` are *NOT* injected into the EntityManagers UnitOfWork, they need to be merged into the EntityManager if it should be reattached to the persistence context in that old version.

### Find Revision History of an audited entity

[](#find-revision-history-of-an-audited-entity)

```
$revisions = $auditReader->findRevisions(
    SimpleThings\EntityAudit\Tests\ArticleAudit::class,
    $id = 1
);
```

A revision has the following API:

```
class Revision
{
    public function getRev();
    public function getTimestamp();
    public function getUsername();
}
```

### Find Changed Entities at a specific revision

[](#find-changed-entities-at-a-specific-revision)

```
$changedEntities = $auditReader->findEntitiesChangedAtRevision(10);
```

A changed entity has the API:

```
class ChangedEntity
{
    public function getClassName();
    public function getId();
    public function getRevisionType();
    public function getEntity();
}
```

### Find Current Revision of an audited Entity

[](#find-current-revision-of-an-audited-entity)

```
$revision = $auditReader->getCurrentRevision(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    $id = 3
);
```

Setting the Current Username
----------------------------

[](#setting-the-current-username)

Each revision automatically saves the username that changes it. For this to work, the username must be resolved.

You can username callable to a specific value using the `AuditConfiguration`.

```
$auditConfig = new \SimpleThings\EntityAudit\AuditConfiguration();
$auditConfig->setUsernameCallable(function () {
	$username = //your customer logic
    return username;
});
```

Supported DB
------------

[](#supported-db)

- MySQL / MariaDB
- PostgesSQL
- SQLite

*We can only really support the databases if we can test them via Travis.*

Contributing
------------

[](#contributing)

Please before commiting, run this command `./vendor/bin/php-cs-fixer fix --verbose` to normalize the coding style.

If you already have the fixer locally you can run `php-cs-fixer fix .`.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/470138?v=4)[David Badura](/maintainers/DavidBadura)[@DavidBadura](https://github.com/DavidBadura)

---

Top Contributors

[![DavidBadura](https://avatars.githubusercontent.com/u/470138?v=4)](https://github.com/DavidBadura "DavidBadura (131 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (53 commits)")[![andrewtch](https://avatars.githubusercontent.com/u/925330?v=4)](https://github.com/andrewtch "andrewtch (40 commits)")[![bendavies](https://avatars.githubusercontent.com/u/625392?v=4)](https://github.com/bendavies "bendavies (36 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (18 commits)")[![merk](https://avatars.githubusercontent.com/u/278097?v=4)](https://github.com/merk "merk (11 commits)")[![Cr8tiveDav](https://avatars.githubusercontent.com/u/114363324?v=4)](https://github.com/Cr8tiveDav "Cr8tiveDav (6 commits)")[![tolry](https://avatars.githubusercontent.com/u/259744?v=4)](https://github.com/tolry "tolry (5 commits)")[![soullivaneuh](https://avatars.githubusercontent.com/u/1698357?v=4)](https://github.com/soullivaneuh "soullivaneuh (5 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (5 commits)")[![tommygnr](https://avatars.githubusercontent.com/u/929392?v=4)](https://github.com/tommygnr "tommygnr (4 commits)")[![tseho](https://avatars.githubusercontent.com/u/1421130?v=4)](https://github.com/tseho "tseho (4 commits)")[![welante](https://avatars.githubusercontent.com/u/547046?v=4)](https://github.com/welante "welante (3 commits)")[![atsiddiqui](https://avatars.githubusercontent.com/u/308345?v=4)](https://github.com/atsiddiqui "atsiddiqui (3 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (3 commits)")[![c0ntax](https://avatars.githubusercontent.com/u/1075300?v=4)](https://github.com/c0ntax "c0ntax (3 commits)")[![JavierJimenez](https://avatars.githubusercontent.com/u/1233868?v=4)](https://github.com/JavierJimenez "JavierJimenez (3 commits)")[![TheRatG](https://avatars.githubusercontent.com/u/1580318?v=4)](https://github.com/TheRatG "TheRatG (3 commits)")[![OskarStark](https://avatars.githubusercontent.com/u/995707?v=4)](https://github.com/OskarStark "OskarStark (2 commits)")[![rvanlaak](https://avatars.githubusercontent.com/u/2707563?v=4)](https://github.com/rvanlaak "rvanlaak (2 commits)")

---

Tags

doctrine-extensiondoctrine-orm

### Embed Badge

![Health badge](/badges/simplethings-entity-audit/health.svg)

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

PHPackages © 2026

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