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

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

clea/hydrator
=============

1.1(8y ago)296MITPHP

Since Sep 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/nicosolo/hydrator)[ Packagist](https://packagist.org/packages/clea/hydrator)[ RSS](/packages/clea-hydrator/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

hydrator
========

[](#hydrator)

Description
-----------

[](#description)

Simple php hydration that support nested objects and collections

Requirements
------------

[](#requirements)

PHP &gt;= 7.0

Installation
------------

[](#installation)

Using composer

```
composer require clea/hydrator

```

how it's work
-------------

[](#how-its-work)

The hydrator base the type of property on the getter return type:

```
public function getName(): string
{
    ...
}
```

This will simply cast the var to string.

The Transformer Class is used for cast or make operation on the value before call the setter.

You can add customs transformer functions see the example section.

For be able to hydrate nested object you have to define the return type of the getter

```
public function getNestedClass(): MyNestedClass
{
    ...
}
```

Usage
-----

[](#usage)

### Options

[](#options)

```
        $settings = [
            "additional_type" => [
               MyNumber::class => function($value){
                    return new MyNumber($value);
               }
               //...
            ],
            "cache" => true
        ];
```

### Example

[](#example)

```
use Clea\Hydrator\Hydrator;

$data = [
    "string" => "value 1",
    "number" => "10",
    "notHydrated" => "test",
    "nested" => [
        "field" => "2017-10-10"
    ],
    "collection" => [
        ["field" => "10.42"],
        ["field" => "10.42"]
    ]
];

$hydrator = new Hydrator();
$data = $this->getUserData();

$user = $hydrator->hydrate(User::class, $data);

```

#### Simple field casted to string

[](#simple-field-casted-to-string)

```
class User
{
    //...

    /**
     * @var string
     */
    private $string;

    /**
     * @return string
     */
    public function getString(): string
    {
        return $this->string;
    }

    //...
}
```

#### Simple field casted to number

[](#simple-field-casted-to-number)

```
class User
{
    //...

    /**
     * @var int
     */
    private $number;

    /**
     * @return int
     */
    public function getNumber(): int
    {
        return $this->number;
    }

    //...
}
```

#### No hydrated field

[](#no-hydrated-field)

```
class User
{
    //...

    /**
    * @noHydrated
    * @var string
    */
    private $notHydrated;

    //...
}
```

#### Nested field

[](#nested-field)

```
class User
{
    //...

    /**
     * @var Nested
     */
    private $nested;

    /**
     * @return Nested
     */
    public function getNested(): Nested
    {
        return $this->nested;
    }

    //...
}
```

#### Collection field

[](#collection-field)

In this case you need to use the same syntax as below, the comment are used for get the type of the entity in the collection

You need to give the full name of your class: \* @var \\MyProject\\Message\[\]

```
class User
{
    //...

    /**
     * @var \MyProject\UserChild[]
     */
    private $collection;

    /**
     * @return \MyProject\UserChild[]
     */
    public function getCollection(): array
    {
        return $this->collection;
    }

    //...
}
```

If you want to contribute feel free to contact me / make a pull request.

The MIT License (MIT). Please see LICENSE for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Total

2

Last Release

3196d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5852487?v=4)[Nicolas Solioz](/maintainers/nicosolo)[@nicosolo](https://github.com/nicosolo)

---

Tags

entityhydratorlibraryphpphp-hydratorhydrator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[cuyz/valinor

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

1.5k11.7M155](/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.

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

Hydrator for PHP 8.0+

12320.2k8](/packages/nutgram-hydrator)[sunrise/hydrator

A flexible strictly-typed hydrator.

2132.4k5](/packages/sunrise-hydrator)

PHPackages © 2026

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