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

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

eag/easy-hydrator
=================

Hydrate arrays to objects easily with PHP 8.0 and constructor injection

1.2.0(7mo ago)149.3k↓16%MITPHPPHP &gt;=8.0

Since Nov 17Pushed 7mo agoCompare

[ Source](https://github.com/Carvago/easy-hydrator)[ Packagist](https://packagist.org/packages/eag/easy-hydrator)[ Fund](https://www.paypal.me/rectorphp)[ GitHub Sponsors](https://github.com/tomasvotruba)[ RSS](/packages/eag-easy-hydrator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (8)Used By (0)

Hydrate Arrays to Objects
=========================

[](#hydrate-arrays-to-objects)

- **easy!**
- PHP 8.0 support
- constructor injection support
- auto-resolving of `DateTimeInterface` string value
- auto-retype based on param type declarations
- nested objects support
- customizable objects creation
- cached

Install
-------

[](#install)

```
composer require eag/easy-hydrator
```

Add to `config/bundles.php`:

```
return [
    EAG\EasyHydrator\EasyHydratorBundle::class => [
        'all' => true,
    ],
];
```

Usage
-----

[](#usage)

Having value object with constructor injection:

```
namespace App\ValueObject;

use DateTimeInterface;

final class Person
{
    private string $name;

    private int $age;

    private DateTimeInterface $metAt;

    public function __construct(string $name, int $age, DateTimeInterface $metAt)
    {
        $this->name = $name;
        $this->age = $age;
        $this->metAt = $metAt;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getAge(): int
    {
        return $this->age;
    }

    public function getMetAt(): DateTimeInterface
    {
        return $this->metAt;
    }
}
```

Use hydrator with array like this:

```
namespace App\Repository;

use App\ValueObject\Person;
use EAG\EasyHydrator\ArrayToValueObjectHydrator;

final class HumanRepository
{
    /**
     * @var ArrayToValueObjectHydrator
     */
    private $arrayToValueObjectHydrator;

    public function __construct(ArrayToValueObjectHydrator $arrayToValueObjectHydrator)
    {
        $this->arrayToValueObjectHydrator = $arrayToValueObjectHydrator;
    }

    public function getPerson(): Person
    {
        return $this->arrayToValueObjectHydrator->hydrateArray([
            'name' => 'Tom',
            // will be retyped to int
            'age' => '30',
            // will be retyped to DateTimeInterface
            'metAt' => '2020-02-02',
        ], Person::class);

        // ...
    }
}
```

### Multiple Value Objects?

[](#multiple-value-objects)

This is how you hydrate 1 item:

```
$singlePersonAsArray = [
    'name' => 'Tom',
    // will be retyped to int
    'age' => '30',
    // will be retyped to DateTimeInterface
    'metAt' => '2020-02-02',
]);

/** @var Person $person */
$person = $this->arrayToValueObjectHydrator->hydrateArray($singlePersonAsArray, Person::class);
```

But how can we hydrate multiple items?

```
$manyPersonsAsArray = [];
$manyPersonsAsArray[] = [
    'name' => 'Tom',
    // will be retyped to int
    'age' => '30',
    // will be retyped to DateTimeInterface
    'metAt' => '2020-02-02',
];

$manyPersonsAsArray[] = [
    'name' => 'John',
    // will be retyped to int
    'age' => '25',
    // will be retyped to DateTimeInterface
    'metAt' => '2019-12-31',
];

/** @var Person[] $persons */
$persons = $this->arrayToValueObjectHydrator->hydrateArrays($manyPersonsAsArray, Person::class);
```

### Optionable values

[](#optionable-values)

If object has optional parameters, and some of their values are not provided in data, default value is used in the hydrated object.

```
class MyObject
{
    private string $foo;

    private string $bar;

    public function __construct(string $foo, string $bar = 'bar')
    {
        $this->foo = $foo;
        $this->bar = $bar;
    }

    public function getFoo(): string
    {
        return $this->foo;
    }

    public function getBar(): string
    {
        return $this->bar;
    }
}

$data = [
    'foo' => 'foo',
];

$object = $this->arrayToValueObjectHydrator->hydrateArray($data, MyObject::class);
// bar
$object->getBar();
```

### Missing constructor data

[](#missing-constructor-data)

When not provided data for required constructor parameter, `EAG\EasyHydrator\Exception\MissingDataException` is thrown.

Report Issues
-------------

[](#report-issues)

In case you are experiencing a bug or want to request a new feature head over to the [Symplify monorepo issue tracker](https://github.com/symplify/symplify/issues)

Contribute
----------

[](#contribute)

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on [symplify/symplify](https://github.com/symplify/symplify).

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance62

Regular maintenance activity

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 86.6% 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 ~279 days

Recently: every ~345 days

Total

6

Last Release

235d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ff6c5d5c42d156e8ba1c241de2b03de9f8390e0604f95796054d39eb199acdb?d=identicon)[carvagobot](/maintainers/carvagobot)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (194 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (18 commits)")[![janatjak](https://avatars.githubusercontent.com/u/11320085?v=4)](https://github.com/janatjak "janatjak (6 commits)")[![player259](https://avatars.githubusercontent.com/u/3974262?v=4)](https://github.com/player259 "player259 (3 commits)")[![jirigracik](https://avatars.githubusercontent.com/u/22130928?v=4)](https://github.com/jirigracik "jirigracik (1 commits)")[![JanMikes](https://avatars.githubusercontent.com/u/3995003?v=4)](https://github.com/JanMikes "JanMikes (1 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[pentatrion/vite-bundle

Vite integration for your Symfony app

2755.3M13](/packages/pentatrion-vite-bundle)[sulu/sulu

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

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

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

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