PHPackages                             mouf/tdbm-hydrator - 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. mouf/tdbm-hydrator

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

mouf/tdbm-hydrator
==================

A PHP hydrator allowing easy mapping between an array and an object.

1.0.x-dev(9y ago)130.4k[2 issues](https://github.com/thecodingmachine/tdbm-hydrator/issues)1MITPHPPHP &gt;=7.0

Since Jul 5Pushed 9y ago6 watchersCompare

[ Source](https://github.com/thecodingmachine/tdbm-hydrator)[ Packagist](https://packagist.org/packages/mouf/tdbm-hydrator)[ Docs](http://mouf-php.com/packages/mouf/tdbm-hydrator)[ RSS](/packages/mouf-tdbm-hydrator/feed)WikiDiscussions 1.0 Synced 2mo ago

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

[![Latest Stable Version](https://camo.githubusercontent.com/787335bb07370076a820395745aa55db189d8af17b4884326cc15f6acb4a4673/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7464626d2d6879647261746f722f762f737461626c65)](https://packagist.org/packages/mouf/tdbm-hydrator)[![Total Downloads](https://camo.githubusercontent.com/9b53e784e17890b34fff701c1fd8c58abef47a97e7a3f730a4425cbfcf7a0c62/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7464626d2d6879647261746f722f646f776e6c6f616473)](https://packagist.org/packages/mouf/tdbm-hydrator)[![Latest Unstable Version](https://camo.githubusercontent.com/bbb28d107882a7224251755297d9d8a9691ab99098fa2c68e120c8380fc08be5/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7464626d2d6879647261746f722f762f756e737461626c65)](https://packagist.org/packages/mouf/tdbm-hydrator)[![License](https://camo.githubusercontent.com/6cde086a6fcbb5dd4894f9b264ab5ea740ed6639a1635d8b14b7e40430124f88/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7464626d2d6879647261746f722f6c6963656e7365)](https://packagist.org/packages/mouf/tdbm-hydrator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ec8a767f8aace2f95d9961f496919ed246107bef6fe3eb580fbf5664fdd563dc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f7464626d2d6879647261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e30)](https://scrutinizer-ci.com/g/thecodingmachine/tdbm-hydrator/?branch=1.0)[![Build Status](https://camo.githubusercontent.com/dcbb392c973297fa81417c3d1392ebc2b339e72bb716f613a262357dac56f4a3/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f7464626d2d6879647261746f722e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/tdbm-hydrator)[![Coverage Status](https://camo.githubusercontent.com/c51cc08cd343f85528ddb0cafed7d681973583c13e4177513a65716753743803/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f7464626d2d6879647261746f722f62616467652e7376673f6272616e63683d312e3026736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/tdbm-hydrator?branch=1.0)

About the TDBM hydrator
=======================

[](#about-the-tdbm-hydrator)

This package contains an **hydrator**. An **hydrator** is a class that takes an array in parameter and maps it to an object (calling the appropriate getters and setters).

Unlike most existing hydrators that need an object instance to be filled, the *tdbm-hydrator* package can (optionally) create a new object instance. This is very useful when you have big constructors with lots of parameters to fill from the array, which happen often if you use [TDBM](http://mouf-php.com/packages/mouf/database.tdbm).

Note that this package is completely standalone and does not need TDBM or Mouf to run. Still, this hydrator is known to work very well with TDBM generated beans (hence the name).

Installation
============

[](#installation)

```
composer require mouf/tdbm-hydrator

```

Usage
=====

[](#usage)

Let's assume you have a simple `Product` class:

```
class Product
{
    private $name;
    private $price;
    private $inStock;

    public function __construct(string $name, float $price)
    {
        $this->name = $name;
        $this->price = $price;
    }

    public function setName(string $name)
    {
        $this->name = $name;
    }

    public function setPrice(float $price)
    {
        $this->price = $price;
    }

    public function setInStock(bool $inStock)
    {
        $this->inStock = $inStock;
    }

    // Let's assume we have getters too...
}
```

Now, I have this PHP array I want to turn into an object:

```
$productAsArray = [
    'name' => 'My product',
    'price' => '99',
    'in_stock' => true
]
```

Creating a new hydrated object
------------------------------

[](#creating-a-new-hydrated-object)

I can create an object ex-nihilo, using the following code:

```
$hydrator = new TdbmHydrator();

$product = $hydrator->hydrateNewObject([
    'name' => 'My product',
    'price' => '99',
    'in_stock' => true
], Product::class);
```

Notice that:

- the `TdbmHydrator` will map each item of the array to the constructor arguments or the setters
- the `TdbmHydrator` can sort out differences between camel-case and underscored names (for instance, it can map `in_stock` to `setInStock()`)

Hydrating an existing object
----------------------------

[](#hydrating-an-existing-object)

I can also fill an existing object with values from an array. In this case, only setters are called:

```
$product = new Project('My product', 99);

$hydrator->hydrateObject([
    'in_stock' => true
], $product);
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

3604d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

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

---

Tags

hydratorTDBM

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mouf-tdbm-hydrator/health.svg)

```
[![Health](https://phpackages.com/badges/mouf-tdbm-hydrator/health.svg)](https://phpackages.com/packages/mouf-tdbm-hydrator)
```

###  Alternatives

[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[samdark/hydrator

Allows to extract data from an object or create a new object based on data for the purpose of persisting state. Works with private and protected properties.

11476.9k](/packages/samdark-hydrator)[nutgram/hydrator

Hydrator for PHP 8.0+

12265.2k6](/packages/nutgram-hydrator)[sunrise/hydrator

A flexible strictly-typed hydrator.

1231.1k4](/packages/sunrise-hydrator)

PHPackages © 2026

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