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

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

gravatalonga/hydrator
=====================

Hydrator class from array to object or objecto to array

1.0.3(5y ago)21671MITPHPPHP ^8.0 || ^7.4

Since Apr 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/gravataLonga/hydrator)[ Packagist](https://packagist.org/packages/gravatalonga/hydrator)[ GitHub Sponsors](https://github.com/gravataLonga)[ RSS](/packages/gravatalonga-hydrator/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (1)

[![Hydrator](Hydrator.jpg)](Hydrator.jpg)

Hydrator
========

[](#hydrator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4462f5564412118ffa61cbd96604af9f84df1998ffb387f002506179e28b1de6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677261766174614c6f6e67612f6879647261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gravataLonga/hydrator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/7b4e7f1294ef1513ed44034a9961be5251292df060790dd17e8b0e5f9ca9b308/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f677261766174614c6f6e67612f6879647261746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/gravataLonga/hydrator)[![Coverage Status](https://camo.githubusercontent.com/ace3b3b42a696bef7c0c3593360f215da4b2e98daed6e18a74a0da5e953cf459/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f677261766174614c6f6e67612f6879647261746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gravataLonga/hydrator/code-structure)[![Quality Score](https://camo.githubusercontent.com/80dea2f9c0e0403204b006be3dbcc0735d9a0a975e2674f037cb49e4250b3e81/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f677261766174614c6f6e67612f6879647261746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gravataLonga/hydrator)[![Total Downloads](https://camo.githubusercontent.com/8e29469b8e3cb7642c103ef2a03cb682070c93572a2a947bd30a2124b7d93d69/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677261766174614c6f6e67612f6879647261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gravataLonga/hydrator)

Hydrator is a library that can help you populate an Data Object properties from array.

Structure
---------

[](#structure)

```
build/
src/
examples/
tests/
vendor/

```

Install
-------

[](#install)

Via Composer

```
$ composer require gravataLonga/hydrator
```

Usage
-----

[](#usage)

```
$properties = ['id' => 1, 'string' => 'hello world']

class Entity implements HydrableInterface
{
    use HydrateTrait;

    public int $id;

    public string $string;
}

$e = Entity::hydrate($property);
echo $e->id; // 1
echo $e->string; // hello world
```

You can even use internal functions to format properly value,

```
$properties = ['name' => 'Jonathan']

class Entity implements HydrableInterface
{
    use HydrateTrait;

    public string $name;

    private function formatName($value)
    {
        return 'Hi, ' . $value;
    }
}

$e = Entity::hydrate($property);
echo $e->string; // Hi, Jonathan
```

**Note**: If property is set private or protected, it will not populate that fields, and it will throw an exception.

If you can't or dislike usage of traits, you have another way, is to use: `Hydrator`.

```
$hydrator = new Hydrator(['id' => 1]);
$entity = $hydrator->hydrate(new Entity);

echo $entity->id; // 1

```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jonathan Fontes](https://github.com/gravataLonga)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

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

Total

4

Last Release

1847d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4ffa38be69914cd6a634e2916246b70931885bd81e64c8c6848950e99c4c791?d=identicon)[gravataLonga](/maintainers/gravataLonga)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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