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

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

tobinfree/hydrator
==================

Simple hydration mechanism via traits

v0.5.0(3y ago)092MITPHPPHP ^8.1CI failing

Since Oct 25Pushed 3y agoCompare

[ Source](https://github.com/2binfree/Hydrator)[ Packagist](https://packagist.org/packages/tobinfree/hydrator)[ RSS](/packages/tobinfree-hydrator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (9)Used By (0)

Hydrator
--------

[](#hydrator)

Simple hydration mechanism. Use the PHP trait to not block inheritance on your classes.

ChangeLog
---------

[](#changelog)

- 0.1.0
    - initial version
- 0.2.0
    - add support of properties of all parent classes
- 0.3.0
    - add null properties filter
- 0.4.0
    - add boolean getter "is" support
- 0.5.0
    - change required php version to php 8.1
    - use Attribute rather than php doc for annotation
    - fix getter and setter detection from parent class

#### Installation :

[](#installation-)

composer require tobinfree/hydrator

#### Usage:

[](#usage)

Add trait in your class :

```
use ToBinFree\Hydrator\Hydrator;

Class User
{
    use Hydrator;

    private int $id;

    private string $name;

    private string $email;
    ...
}

```

Hydrator search all accessors and mutators methods from class properties. If the methods are not found, the property will be used directly.

You can block the direct use of properties and force the use of the methods with:

```
    $user = new User();
    $user->setMutatorOnly(true); // for set method usage only
    $user->setAccessorOnly(true); // for get method usage only

```

Now, you can generate an array from your object :

```
    var_dump($user->toArray());

```

You can specify witch properties will be generated using annotation @DataProperty :

```
use ToBinFree\Hydrator\Hydrator;

Class User
{
    use Hydrator;

    private int $id

    #[DataProperty]
    private string $name;

    #[DataProperty]
    private string $email;
    ...
}

```

```
    var_dump($user->toArray(true));

```

And you can hydrate your object with an array :

```
    $user->hydrate([
        "name" => "Eric",
        "email" => "eric@email.com"
    ]);

```

By default, null values properties are included. You can filter null properties with `withNullValue` option :

```
    $user->hydrate($array, true, false);
    var_dump($user->toArray(true, false));

```

#### License

[](#license)

This bundle is under the MIT license. See the complete license in the bundle.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~215 days

Recently: every ~286 days

Total

8

Last Release

1301d ago

PHP version history (4 changes)v0.1.0PHP &gt;=5.3.0

v0.2.0PHP &gt;=7.1.0

v0.3.0PHP ^7.2

v0.5.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19702772?v=4)[Laurent Aubertin](/maintainers/2binfree)[@2binfree](https://github.com/2binfree)

---

Top Contributors

[![2binfree](https://avatars.githubusercontent.com/u/19702772?v=4)](https://github.com/2binfree "2binfree (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shapecode/hidden-entity-type-bundle

Hidden field for Symfony entities

28448.1k1](/packages/shapecode-hidden-entity-type-bundle)

PHPackages © 2026

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