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

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

thecodingmachine/fluid-hydrator
===============================

A fluid builder for MetaHydrator class

1.x-dev(7y ago)34.1k3[1 issues](https://github.com/thecodingmachine/fluid-hydrator/issues)[2 PRs](https://github.com/thecodingmachine/fluid-hydrator/pulls)MITPHP

Since Sep 27Pushed 7y agoCompare

[ Source](https://github.com/thecodingmachine/fluid-hydrator)[ Packagist](https://packagist.org/packages/thecodingmachine/fluid-hydrator)[ RSS](/packages/thecodingmachine-fluid-hydrator/feed)WikiDiscussions 1.x Synced 4w ago

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

FluidHydrator
=============

[](#fluidhydrator)

*This package is based on [thecodingmachine/metahydrator](https://packagist.org/packages/thecodingmachine/metahydrator), and aims to ease instantiation code (ie when not using dependency injection). In order to do so, it follows fluent design pattern.*

How to use
----------

[](#how-to-use)

As you have probably deduced by now, the main class of this package is `FluidHydrator`. It implements interface `Hydrator`(refer to [mouf/tdbm-hydrator](https://packagist.org/packages/mouf/tdbm-hydrator) for more details).

```
$hydrator = new FluidHydrator;
```

### Primitive types

[](#primitive-types)

Use method `field` to declare a primitive field. Then, declare its type using `int()`, `bool()`, `string()`, etc.

```
$hydrator->field('foo')->int();
```

To declare an unstructured array field (typically some decoded JSON), use the `simpleArray` function.

```
$hydrator->field('foo')->simpleArray();
```

As we are these can be chained as following:

```
$hydrator
    ->field('foo')->string()->then()
    ->field('bar')->int() // Note that call o method then() is optional!
    ->field('baz')->float()
;
```

A type method leads to a state where you may add options to the field, mostly validators.

```
$hydrator
    ->field('foo')->string()->required()->maxLength(55)
;
```

### Array

[](#array)

Option `array()` allows to change the current type from T to array, where current validators are used for validating each entry. These can be used multiple times.

```
$hydrator
    // 'foo' must be an array of non-empty arrays containing non-empty strings of length inferior to 55
    ->field('foo')->string()->required()->maxLength(55)->array()->required()->array()
;
```

### Object types

[](#object-types)

You may also use a non-primitive type (ie a class) for a `field()`. Method `object()` then needs you to specify the hydrator used to parse the sub-data. You may pass an existant hydrator using method `hydrator()`

```
$hydrator
    ->field('garply')->object(Garply::class)->hydrator($garplyHydrator)
;
```

or even use default hydrator (being TDBMHydrator), if you do not wish to check the data sanity

```
$hydrator
    ->field('garply')->object(Garply::class)->hydrator()
;
```

If you want to declare the sub-hydrator on the fly, you can: declare it between a `begin()` and a `end()`

```
$hydrator
    ->field('garply')->object(Garply::class)
    ->begin()
        ->field('qux')->string()
        ->field('quux')->bool()
    ->end()
;
```

Note that after `end()` or `hydrator()`, you are in the same state as when typing a primitive field. Therefore, you can add validators, and even switch from T to T\[\] with `array()`!

### Sub-Object

[](#sub-object)

In some cases, you will want to access sub-objects from the top-level value being hydrated. This way, the existing value will not be replaced, but directly hydrated, respecting references and allowing partial edition.

The field type you're looking for here is `subobject()`; the writing is substantially similar to `object()`, except for the option `array()` that you should not used, since it's not (yet) supported.

```
$hydrator
    ->field('garply')->subobject(Garply::class)
    ->begin()
        ->field('qux')->string()
        ->field('quux')->bool()
    ->end()->required()
;
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

2794d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![llebacq](https://avatars.githubusercontent.com/u/18592688?v=4)](https://github.com/llebacq "llebacq (9 commits)")[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (8 commits)")[![dsavina](https://avatars.githubusercontent.com/u/22031211?v=4)](https://github.com/dsavina "dsavina (4 commits)")[![brain-diminished](https://avatars.githubusercontent.com/u/10856512?v=4)](https://github.com/brain-diminished "brain-diminished (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bruli/php-git-hooks

Git hooks for PHP projects.

669372.2k5](/packages/bruli-php-git-hooks)[elgentos/category-tiling

Adds tiling display option to categories for showing sub-categories as tiles

2137.4k](/packages/elgentos-category-tiling)

PHPackages © 2026

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