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

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

symplify/easy-hydrator
======================

Hydrate arrays to objects easily with PHP 7.4 and constructor injection

9.4.70(4y ago)3081.5k3MITPHPPHP &gt;=8.0

Since Apr 8Pushed 4y ago3 watchersCompare

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

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

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

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

[![Downloads total](https://camo.githubusercontent.com/89d7fee2c9a5080765a2b626ce5e4f8be8cb1d7514dee68680e4a22acf569b57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73796d706c6966792f656173792d6879647261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/symplify/easy-hydrator/stats)

- **easy!**
- PHP 7.4 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 symplify/easy-hydrator
```

Add to `config/bundles.php`:

```
return [
    Symplify\EasyHydrator\EasyHydratorBundle::class => [
        'all' => true,
    ],
    Symplify\SimplePhpDocParser\Bundle\SimplePhpDocParserBundle::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 Symplify\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, `Symplify\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

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 89.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 ~1 days

Total

320

Last Release

1689d ago

Major Versions

v7.3.18 → v8.0.0-beta12020-05-16

8.3.48 → 9.0.0-BETA12020-11-14

PHP version history (5 changes)v7.2.10PHP ^7.2

8.2.17PHP ^7.2|^8.0

8.3.0PHP &gt;=7.2

9.0.0-rc1PHP &gt;=7.3

v9.3.27PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

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 (3 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)")

---

Tags

constructor-injectionhydrate-arrayshydratorphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19280.3k3](/packages/symfony-ux-cropperjs)

PHPackages © 2026

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