PHPackages                             rekalogika/reconstitutor - 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. rekalogika/reconstitutor

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

rekalogika/reconstitutor
========================

A thin layer above Doctrine events to help you reconstitute/hydrate your entities. The most common example being handling file uploads, but also many other purposes. It lets you augment Doctrine's hydration with your logic in a concise and expressive class.

2.4.0(11mo ago)513.2k↑20%1MITPHPPHP ^8.2CI passing

Since Sep 17Pushed 11mo ago2 watchersCompare

[ Source](https://github.com/rekalogika/reconstitutor)[ Packagist](https://packagist.org/packages/rekalogika/reconstitutor)[ Docs](https://rekalogika.dev/reconstitutor)[ GitHub Sponsors](https://github.com/priyadi)[ RSS](/packages/rekalogika-reconstitutor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (27)Versions (16)Used By (1)

rekalogika/reconstitutor
========================

[](#rekalogikareconstitutor)

This library provides a thin layer that sits above Doctrine events to help you reconstitute/hydrate your entities. It lets you augment Doctrine's hydration with your logic in a concise and expressive class.

Full documentation: [rekalogika.dev/reconstitutor](https://rekalogika.dev/reconstitutor)

After Doctrine hydrates an object from the database, this framework gives you the control to hydrate additional properties not handled by Doctrine, without having to deal with the peculiarities of Doctrine events and Unit of Work. Then, after Doctrine persists the changes to the database, it lets you do similarly with the properties.

The most common case of this type of tasks is for handling file uploads, of which many specialized libraries have already been written. But plenty of other cases exist:

- A lazy-loading proxy that fetches the real resource using an API call.
- Linking objects that are managed by different object managers, or non-Doctrine entities.

These days, we usually call the process *hydration*. *Reconstitution* is the term used by Eric Evans in *"Domain-Driven Design: Tackling Complexity in the Heart of Software"*.

Features
--------

[](#features)

- Streamlines a very specific, yet very common use case of Doctrine events.
- Simple declaration in a class. You can create a reconstitutor class to handle the reconstitution of a specific entity class, entities that implement a specific interface, entities in a class hierarchy, or those with a specific PHP attribute.
- Our abstract classes provide `get()` and `set()` methods as a convenience. They let you work with the properties directly, bypassing getters and setters. It is the best practice in reconstitutions as it frees you to have business logic in the getters and setters.
- The `get()` and `set()` methods are forwarders to a custom implementation of Symfony's `PropertyAccessorInterface`. Therefore, you can use the same exceptions defined in `PropertyAccessorInterface`.
- Abstracts all the peculiarities of Doctrine events, unit of work, database transactions, and proxy, so you don't have to find out and deal with them yourself.
- It asks your reconstitutor to save only after Doctrine has successfully saved the object.
- Does not rely on Doctrine seeing the object being dirty before `flush()`-ing. i.e. your entities don't have to modify a Doctrine-managed property —like `$lastUpdated`— just to make sure the correct Doctrine event will be fired.
- Handles transactions. In a transaction, it will only ask your reconstitutor to save or remove after the transaction has been successfully committed.

Example
-------

[](#example)

A very simple file upload handling:

```
use Rekalogika\Reconstitutor\AbstractClassReconstitutor;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
 * @extends AbstractClassReconstitutor
 */
final class OrderReconstitutor extends AbstractClassReconstitutor
{
    /**
     * The class that this reconstitutor manages. It can also be a super class
     * or an interface.
     */
    public static function getClass(): string
    {
        return Order::class;
    }

    /**
     * When the object is being saved, we check if the paymentReceipt has been
     * just uploaded. If it is, we save it to a file.
     *
     * Note: in Symfony, an uploaded file is represented by an instance of
     * `UploadedFile`, otherwise it will be a `File` object.
     */
    public function onSave(object $order): void
    {
        $path = sprintf('/tmp/payment_receipt/%s', $order->getId());

        $file = $this->get($order, 'paymentReceipt');

        if ($file instanceof UploadedFile) {
            file_put_contents($path, $file->getContent());
            $this->set($order, 'paymentReceipt', new File($path));
        }
    }

    /**
     * When the object is being loaded from the database, we check if the
     * supposed payment receipt is already saved. If it is, then we load the
     * file to the property.
     */
    public function onLoad(object $order): void
    {
        $path = sprintf('/tmp/payment_receipt/%s', $order->getId());

        if (file_exists($path)) {
            $file = new File($path);
        } else {
            $file = null;
        }

        $this->set($order, 'paymentReceipt', $file);
    }

    /**
     * If the order is being removed, we remove the associated payment receipt
     * here.
     */
    public function onRemove(object $order): void
    {
        $path = sprintf('/tmp/payment_receipt/%s', $order->getId());

        if (file_exists($path)) {
            unlink($path);
        }
    }
}
```

Documentation
-------------

[](#documentation)

[rekalogika.dev/reconstitutor](https://rekalogika.dev/reconstitutor)

License
-------

[](#license)

MIT

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

[](#contributing)

Issues and pull requests should be filed in the GitHub repository [rekalogika/reconstitutor](https://github.com/rekalogika/reconstitutor).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance52

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% 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 ~26 days

Recently: every ~9 days

Total

11

Last Release

340d ago

Major Versions

1.4.0 → 2.0.02025-05-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/13d0eed333cf2f0d552e9a4d0ca1c6a8fc0be0506bbc5e7516f6985b17b86043?d=identicon)[priyadi](/maintainers/priyadi)

---

Top Contributors

[![priyadi](https://avatars.githubusercontent.com/u/1102197?v=4)](https://github.com/priyadi "priyadi (68 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

doctrinehydrationphpreconstitutionsymfonysymfony-bundle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rekalogika-reconstitutor/health.svg)

```
[![Health](https://phpackages.com/badges/rekalogika-reconstitutor/health.svg)](https://phpackages.com/packages/rekalogika-reconstitutor)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)

PHPackages © 2026

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