PHPackages                             kenny1911/doctrine-aggrolock - 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. kenny1911/doctrine-aggrolock

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

kenny1911/doctrine-aggrolock
============================

Doctrine ORM extension, that supports optimistic lock for aggregate entities

0.1.x-dev(1y ago)01.7k↓17.8%MITPHPPHP ^8.1

Since Feb 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Kenny1911/doctrine-aggrolock)[ Packagist](https://packagist.org/packages/kenny1911/doctrine-aggrolock)[ RSS](/packages/kenny1911-doctrine-aggrolock/feed)WikiDiscussions 0.1.x Synced today

READMEChangelogDependencies (3)Versions (1)Used By (0)

DoctrineAggroLock
=================

[](#doctrineaggrolock)

**DoctrineAggroLock** is **Doctrine ORM** extension that adds support optimistic lock of aggregate entities (associations). **DoctrineAggroLock** prevents data loss during concurrent changes using an aggregate versioning mechanism.

Features
--------

[](#features)

- Optimistic lock for aggregates and their associations
- Integration with Doctrine ORM
- Configuration via interfaces (`AggregateRoot` and `AggregateEntity`)
- Automatic aggregates versioning
- DDD (Domain-Driven Design) support

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

[](#installation)

```
composer require kenny1911/doctrine-aggrolock
```

Register the Doctrine Event Subscriber `Kenny1911\DoctrineAggroLock\AggroLock`.

Symfony Framework Example:

```
services:

  Kenny1911\DoctrineAggroLock\AggregateEntitySubscriber:
    tags:
      - name: doctrine.event_subscriber
```

Example
-------

[](#example)

**Aggregate Root:**

```
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use Kenny1911\DoctrineAggroLock\AggregateRoot;
use Ramsey\Uuid\UuidInterface as Uuid;

/**
 * @final
 */
#[ORM\Entity]
class Order implements AggregateRoot
{
    #[ORM\Version]
    #[ORM\Column(type: 'integer')]
    private int $version = 1;

    /** @var Collection */
    #[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'order', cascade: ['persist', 'remove'], orphanRemoval: true)]
    private Collection $items;

    public function __construct(
        #[ORM\Id]
        #[ORM\Column(type: 'uuid')]
        private Uuid $id,
    ) {
        $this->id = $id;
        $this->customerName = $customerName;
        $this->items = new ArrayCollection();
    }

    /**
     * @param non-negative-int $quantity
     * @param non-negative-int $price
     */
    public function addItem(Uuid $productId, int $quantity, int $price): void
    {
        $this->items->add(new OrderItem($this, $productId, $quantity, $price)); // TODO
    }

    /**
     * @return ReadableCollection
     */
    public function getItems(): ReadableCollection
    {
        return $this->items;
    }
}
```

**Aggregate Entity**

```
use Doctrine\ORM\Mapping as ORM;
use Kenny1911\DoctrineAggroLock\AggregateEntity;
use Kenny1911\DoctrineAggroLock\AggregateRoot;
use Ramsey\Uuid\UuidInterface as Uuid;

/**
 * @final
 */
#[ORM\Entity]
class OrderItem implements AggregateEntity
{
    /**
     * @param non-negative-int $quantity
     * @param non-negative-int $price
     */
    public function __construct(
        #[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'items')]
        private Order $order,

        #[ORM\Column(type: 'uuid')]
        private Uuid $productId,

        #[ORM\Column(type: 'integer')]
        private int $quantity,

        #[ORM\Column(type: 'integer')]
        private float $price
    ) {}

    public function getAggregateRoot(): AggregateRoot
    {
        return $this->order;
    }
}
```

### Explanations

[](#explanations)

1. **Aggregate Root** (`Order`) implements the `AggregateRoot` interface. It guarantees that the object is the root of the aggregate and not just an entity.
2. **Aggregate Entities** (`OrderItem`) implement the `AggregateEntity` interface and are associated with the aggregate root through a `ManyToOne` relation.
3. **Optimistic Locking** is implemented using the standard **Doctrine ORM** approach with a special version field (`version`).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance40

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 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

511d ago

### Community

Maintainers

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

---

Top Contributors

[![Kenny1911](https://avatars.githubusercontent.com/u/25887351?v=4)](https://github.com/Kenny1911 "Kenny1911 (7 commits)")

---

Tags

doctrineentitydddlockrelationoptimisticaggregaterootassociation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kenny1911-doctrine-aggrolock/health.svg)

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

###  Alternatives

[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[api-platform/doctrine-orm

Doctrine ORM bridge

294.4M92](/packages/api-platform-doctrine-orm)[doctrineencryptbundle/doctrine-encrypt-bundle

Encrypted symfony entity's by verified and standardized libraries

32510.9k](/packages/doctrineencryptbundle-doctrine-encrypt-bundle)

PHPackages © 2026

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