PHPackages                             bentools/doctrine-watcher - 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-watcher

AbandonedLibrary[Database &amp; ORM](/categories/database)

bentools/doctrine-watcher
=========================

Watch changes in your Doctrine entities to let you trigger custom events.

0.2(7y ago)11.3kMITPHPPHP &gt;=7.1

Since Nov 26Pushed 7y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (7)Versions (4)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/4ea79366fbf73ae8e7f9f48c3c6acc354b60ca66edca4c5bf7415b2c2827001e/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f646f637472696e652d776174636865722f762f737461626c65)](https://packagist.org/packages/bentools/doctrine-watcher)[![License](https://camo.githubusercontent.com/1bd9731752f796b927899b1a9e9eb8c12c5ab5a4818c1a35ebe475c3f9c5c612/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f646f637472696e652d776174636865722f6c6963656e7365)](https://packagist.org/packages/bentools/doctrine-watcher)[![Build Status](https://camo.githubusercontent.com/c92edd6f24d682a4108e72a75206e8bc57009d61fe0aa3ba49f8122d8547438f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62706f6c61737a656b2f646f637472696e652d776174636865722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bpolaszek/doctrine-watcher)[![Quality Score](https://camo.githubusercontent.com/d4dbecad426eebe73337c512f92c6bb0725f3a74d606dfcf5a7c7dce9623ca61/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62706f6c61737a656b2f646f637472696e652d776174636865722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bpolaszek/doctrine-watcher)[![Total Downloads](https://camo.githubusercontent.com/45519f052131172a9daabd8eb04931c044157f02162c8fbac001b5139a56724b/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f646f637472696e652d776174636865722f646f776e6c6f616473)](https://packagist.org/packages/bentools/doctrine-watcher)

Doctrine Watcher
================

[](#doctrine-watcher)

This little library will help you to monitor changes on Doctrine insertions and/or updates, for specific classes, for specific properties.

Usage
-----

[](#usage)

```
use App\Entity\User;
use BenTools\DoctrineWatcher\Changeset\PropertyChangeset;
use BenTools\DoctrineWatcher\Watcher\DoctrineWatcher;

/**
 * Instanciate watcher
 */
$watcher = new DoctrineWatcher();

/**
 * Register it as an event subscriber
 * @var \Doctrine\Common\EventManager $eventManager
 */
$eventManager->addEventSubscriber($watcher);

/**
 * Watch for changes on the $email property for the User class
 */
$watcher->watch(User::class, 'email', function (
    PropertyChangeset $changeset,
    string $operationType,
    User $user
) {

    if (!$changeset->hasChanges()) {
        return;
    }

    vprintf('Changed email from %s to %s for user %s' . PHP_EOL, [
        $changeset->getOldValue(),
        $changeset->getNewValue(),
        $user->getName(),
    ]);
});

/**
 * Watch for changes on the $roles property for the User class
 */
$watcher->watch(User::class, 'roles', function (
    PropertyChangeset $changeset,
    string $operationType,
    User $user
) {

    if ($changeset::INSERT === $operationType) {
        return;
    }

    if ($changeset->hasAdditions()) {
        vprintf('Roles %s were granted for user %s' . PHP_EOL, [
            implode(', ', $changeset->getAdditions()),
            $user->getName(),
        ]);
    }

    if ($changeset->hasRemovals()) {
        vprintf('Roles %s were revoked for user %s' . PHP_EOL, [
            implode(', ', $changeset->getRemovals()),
            $user->getName(),
        ]);
    }
});
```

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

[](#installation)

PHP7.1+ is required.

```
composer require bentools/doctrine-watcher:0.2.*
```

Tests
-----

[](#tests)

> ./vendor/bin/phpunit

F.A.Q.
------

[](#faq)

### Can I also trigger callable on insertions ?

[](#can-i-also-trigger-callable-on-insertions-)

```
$watcher = new DoctrineWatcher(['trigger_on_persist' => true]); // Will be default config for all watchers
```

or

```
$watcher->watch(Entity::class, 'property', $callable, ['trigger_on_persist' => true]); // Will apply on this watcher only
```

### How do I trigger something even when there are no changes?

[](#how-do-i-trigger-something-even-when-there-are-no-changes)

```
$watcher = new DoctrineWatcher(['trigger_when_no_changes' => true]); // Will be default config
```

or

```
$watcher->watch(Entity::class, 'property', $callable, ['trigger_when_no_changes' => true]); // Will apply on this watcher only
```

### When are the callback triggered?

[](#when-are-the-callback-triggered)

On `postPersist` and `postUpdate` events.

License
-------

[](#license)

MIT

See also
--------

[](#see-also)

[bentools/doctrine-watcher-bundle](https://github.com/bpolaszek/doctrine-watcher-bundle) - A Symfony Bundle for this library

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Every ~0 days

Total

3

Last Release

2726d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acdd1a8ee0e657ddd06cf11f98a32100ef7121afb8aa270a5b295f5c29c038b3?d=identicon)[bpolaszek](/maintainers/bpolaszek)

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (8 commits)")

---

Tags

ormdoctrineentitychangeswatcherentitieswatchchangechangeset

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bentools-doctrine-watcher/health.svg)

```
[![Health](https://phpackages.com/badges/bentools-doctrine-watcher/health.svg)](https://phpackages.com/packages/bentools-doctrine-watcher)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[vlucas/spot2

Simple DataMapper built on top of Doctrine DBAL

605392.8k7](/packages/vlucas-spot2)[ergebnis/factory-bot

Provides a fixture factory for doctrine/orm entities.

81702.8k](/packages/ergebnis-factory-bot)[indaxia/doctrine-orm-transformations

Provides JSON-ready Doctrine ORM Entity-Array transfomtaions

1296.4k](/packages/indaxia-doctrine-orm-transformations)[andsalves/doctrine-elastic

Elasticsearch Doctrine Adaptation

156.6k](/packages/andsalves-doctrine-elastic)

PHPackages © 2026

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