PHPackages                             hostnet/entity-blamable-component - 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. hostnet/entity-blamable-component

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

hostnet/entity-blamable-component
=================================

Listens to an event so auditable information can be set

1.0.7(1y ago)3140.7k↓13.5%21MITPHPPHP ^7.3|^8.0CI passing

Since Aug 12Pushed 1y ago4 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (11)Used By (1)

README
======

[](#readme)

- [What is the Entity Blamable?](#what-is-the-entity-blamable-component)
- [Requirements](#requirements)
- [Installation](#installation)

### Documentation

[](#documentation)

- [How does it work?](#how-does-it-work)
- [Setup](#setup)
    - [Registering the Events](#registering-the-events)
    - [Creating a Provider for the Username and Timestamp](#creating-a-provider-for-the-username-and-timestamp)
    - [Configuring the Entity](#configuring-the-entity)
    - [What's Next?](#whats-next)

What is the Entity Blamable Component?
--------------------------------------

[](#what-is-the-entity-blamable-component)

The Entity Blamable Component is a library that utilizes the [Entity Tracker Component](https://github.com/hostnet/entity-tracker-component/) and lets you hook in to the entityChanged event.

This component lets you automatically update entities by implementing `setUpdatedAt()`, `setUpdatedBy` and `setCreatedAt()`. At the given time, you have to implement all of them. If you need only 1 or 2 of the methods, pull requests are always allowed. It's not implemented yet due to lack of requirements for our use-cases.

Requirements
------------

[](#requirements)

The blamable component requires a minimum of php 5.4 and runs on Doctrine2. For specific requirements, please check [composer.json](../master/composer.json).

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

[](#installation)

Installing is pretty easy, this package is available on [packagist](https://packagist.org/packages/hostnet/entity-blamable-component). You can register the package locked to a major as we follow [Semantic Versioning 2.0.0](http://semver.org/).

#### Example

[](#example)

```
    "require" : {
        "hostnet/entity-blamable-component" : "1.*"
    }
```

> Note: You can use dev-master if you want the latest changes, but this is not recommended for production code!

Documentation
=============

[](#documentation-1)

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

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

It works by putting the `@Blamable` annotation and BlamableInterface on your Entity and registering the listener on the entityChanged event, assuming you have already configured the [Entity Tracker Component](https://github.com/hostnet/entity-tracker-component/#setup).

For a usage example, follow the setup below.

Setup
-----

[](#setup)

- You have to add `@Blamable` to your entity
- You have to add the BlamableInterface to your entity
- You have to implement the BlamableProviderInterface on an object and pass it to the listener

#### Registering the events

[](#registering-the-events)

Here's an example of a very basic setup. Setting this up will be a lot easier if you use a framework that has a Dependency Injection Container.

It might look a bit complicated to set up, but it's pretty much setting up the tracker component for the most part. If you use it in a framework, it's recommended to create a framework specific configuration package for this to automate this away.

> Note: If you use Symfony2, you can take a look at the [hostnet/entity-tracker-bundle](https://github.com/hostnet/entity-tracker-bundle). This bundle is designed to configure the services for you.

```
use Acme\Bundle\AcmeBundle\Service\AcmeBlamableProvider;
use Hostnet\Component\EntityBlamable\Listener\BlamableListener;
use Hostnet\Component\EntityBlamable\Resolver\BlamableResolver;
use Hostnet\Component\EntityTracker\Listener\EntityChangedListener;
use Hostnet\Component\EntityTracker\Provider\EntityAnnotationMetadataProvider;
use Hostnet\Component\EntityTracker\Provider\EntityMutationMetadataProvider;

/* @var $em \Doctrine\ORM\EntityManager */
$event_manager = $em->getEventManager();

// default doctrine annotation reader
$annotation_reader = new AnnotationReader();

// setup required providers
$mutation_metadata_provider   = new EntityMutationMetadataProvider($annotation_reader);
$annotation_metadata_provider = new EntityAnnotationMetadataProvider($annotation_reader);

// pre flush event listener that uses the @Tracked/@Blamable annotation
$entity_changed_listener = new EntityChangedListener(
    $mutation_metadata_provider,
    $annotation_metadata_provider
);

// the resolver is used to find the correct annotation
$blamable_resolver = new BlamableResolver($annotation_metadata_provider);

// the object that will provide the username and date time. This is an
// application specific implementation of the BlamableProviderInterface
$blamable_provider = new AcmeBlamableProvider();

// creating the blamable listener
$blamable_listener = new BlamableListener($blamable_resolver, $blamable_provider);

// register the events
$event_manager->addEventListener('preFlush', $entity_changed_listener);
$event_manager->addEventListener('entityChanged', $blamable_listener);
```

#### Creating a Provider for the Username and Timestamp

[](#creating-a-provider-for-the-username-and-timestamp)

The provider is used to feed the required values to the BlamableListener, this is the only interface that requires a custom implementation in your project.

> Note that in the example the username is defined as constructor param, but you might want to inject something that contains the currently logged in user and get that identifier.

```
namespace Acme\Bundle\AcmeBundle\Service;

use Hostnet\Component\EntityBlamable\Provider\BlamableProviderInterface;

class AcmeBlamableProvider implements BlamableProviderInterface
{
    private $username;

    public function __construct($username)
    {
        $this->username = $username;
    }

    public function getUpdatedBy()
    {
        return $this->username;
    }

    public function getChangedAt()
    {
        return new \DateTime();
    }
}
```

#### Configuring the Entity

[](#configuring-the-entity)

All we have to do now is put the `@Blamable` annotation and BlamableInterface on our Entity.

```
use Doctrine\ORM\Mapping as ORM;
use Hostnet\Component\EntityBlamable\Blamable;
use Hostnet\Component\EntityBlamable\BlamableInterface;

/**
 * @ORM\Entity
 * @Blamable
 */
class MyEntity implements BlamableInterface
{
    /**
     * @ORM\...
     */
    private $updated_by;

    /**
     * @ORM\...
     */
    private $updated_at;

    /**
     * @ORM\...
     */
    private $created_at;

    public function setUpdatedBy($by)
    {
        $this->updated_by = $by;
    }

    public function setUpdatedAt(\DateTime $at)
    {
        $this->changed_at = $at;
    }

    public function setCreatedAt(\DateTime $at)
    {
        $this->created_at = $at
    }
}
```

### What's next?

[](#whats-next)

```
$entity->setName('henk');
$em->flush();
// Voila, your updated_at and updated_by are filled in (and if it's new, created_at too).
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance42

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~426 days

Recently: every ~777 days

Total

10

Last Release

461d ago

Major Versions

0.0.2 → 1.0.02014-09-09

PHP version history (4 changes)0.0.1PHP 5.\*, &gt;=5.4

1.0.1PHP &lt;8, &gt;=5.4

1.0.2PHP 5.\*,&gt;=5.6||7.\*

1.0.4PHP ^7.3|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5468127?v=4)[Yannick de Lange](/maintainers/yannickl88)[@yannickl88](https://github.com/yannickl88)

![](https://www.gravatar.com/avatar/65433e1ef6edb2e8f96e18614b6618c84eed20ad0de6de0d0da36a9032ec7a18?d=identicon)[hostnet](/maintainers/hostnet)

---

Top Contributors

[![yannickl88](https://avatars.githubusercontent.com/u/5468127?v=4)](https://github.com/yannickl88 "yannickl88 (8 commits)")[![janlam7](https://avatars.githubusercontent.com/u/5459235?v=4)](https://github.com/janlam7 "janlam7 (5 commits)")[![nicoschoenmaker](https://avatars.githubusercontent.com/u/1469323?v=4)](https://github.com/nicoschoenmaker "nicoschoenmaker (3 commits)")[![nutama](https://avatars.githubusercontent.com/u/9001392?v=4)](https://github.com/nutama "nutama (2 commits)")[![linaori](https://avatars.githubusercontent.com/u/1754678?v=4)](https://github.com/linaori "linaori (2 commits)")[![StijnKlopper2k](https://avatars.githubusercontent.com/u/198602351?v=4)](https://github.com/StijnKlopper2k "StijnKlopper2k (1 commits)")[![stefanlenselink](https://avatars.githubusercontent.com/u/834562?v=4)](https://github.com/stefanlenselink "stefanlenselink (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hostnet-entity-blamable-component/health.svg)

```
[![Health](https://phpackages.com/badges/hostnet-entity-blamable-component/health.svg)](https://phpackages.com/packages/hostnet-entity-blamable-component)
```

###  Alternatives

[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[hostnet/entity-tracker-component

Provides an event when a Tracked entity changes

16158.1k4](/packages/hostnet-entity-tracker-component)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)[kibatic/datagrid-bundle

Datagrid for Symfony

1418.3k](/packages/kibatic-datagrid-bundle)

PHPackages © 2026

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