PHPackages                             thecodingmachine/metahydrator - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. thecodingmachine/metahydrator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

thecodingmachine/metahydrator
=============================

A configurable implementation of mouf's Hydrator interface

1.x-dev(7y ago)64.8k5[1 issues](https://github.com/thecodingmachine/metahydrator/issues)[1 PRs](https://github.com/thecodingmachine/metahydrator/pulls)1MITPHPPHP &gt;=7.0

Since Nov 6Pushed 7y agoCompare

[ Source](https://github.com/thecodingmachine/metahydrator)[ Packagist](https://packagist.org/packages/thecodingmachine/metahydrator)[ Docs](http://www.github.com/dsavina/metahydrator)[ RSS](/packages/thecodingmachine-metahydrator/feed)WikiDiscussions 1.x Synced 4w ago

READMEChangelogDependencies (3)Versions (1)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/53e610c4024531dc55f03e9be2dfdd8877438d1e9ad43344838724c0be47998a/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6d6574616879647261746f722f762f737461626c65)](https://packagist.org/packages/thecodingmachine/metahydrator)[![Total Downloads](https://camo.githubusercontent.com/019116a49beb90529a37d0d7459488ff90af857378612edf3d0cc04ff5f42218/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6d6574616879647261746f722f646f776e6c6f616473)](https://packagist.org/packages/thecodingmachine/metahydrator)[![Latest Unstable Version](https://camo.githubusercontent.com/24d1dad93a094976d9c4453fd84bd3b75961d294844563382041047c1b6d493c/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6d6574616879647261746f722f762f756e737461626c65)](https://packagist.org/packages/thecodingmachine/metahydrator)[![License](https://camo.githubusercontent.com/35e0d1b34ef81a66e8a43a03d55db82fcb7a1994410f94ae93489ded22fc9a99/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6d6574616879647261746f722f6c6963656e7365)](https://packagist.org/packages/thecodingmachine/metahydrator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/799c6be0c5303f8de9e1e34b48c7fd26d73b47e7f3c7870f1d5a2e55f1ca8cd9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f6d6574616879647261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e78)](https://scrutinizer-ci.com/g/thecodingmachine/metahydrator/?branch=1.x)[![Build Status](https://camo.githubusercontent.com/af1d4ad9df9d3c3a9a83e0e7f3ceb3c8c03a7a0f506cce4dfda5eafc4f15d5f7/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f6d6574616879647261746f722e7376673f6272616e63683d312e78)](https://travis-ci.org/thecodingmachine/metahydrator)[![Coverage Status](https://camo.githubusercontent.com/897861ebb84edfec17add88679e26006582f2ceaa62fcb8d4020294771452680/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f6d6574616879647261746f722f62616467652e7376673f6272616e63683d312e7826736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/metahydrator?branch=1.x)

About hydrating
===============

[](#about-hydrating)

This package aims to help handling raw data (associative arrays of basic types) for editing and creating instances of whatever-the-class-you-want. Therefore, a class offering a solution to this purpose should implement interface `Hydrator`, ie methods `hydrateObject`and `hydrateNewObject`.

- method `hydrateNewObject` should create an instance of requested class, using parsed data to set its values.
- method `hydrateObject` should edit a given object, setting its properties using parsed data. This package offers a generic implementation of `Hydrator`, `MetaHydrator`, designed to work specifically with [Mouf](http://mouf-php.com/).

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

[](#how-to-use)

The main interest of this package is to avoid unpleasant and interminable hours of writing repetitive lines of code to describe how to manage some innput data (ie validate, parse and instantiate from it), and instead make the creation of a data handler a simple configuration task. Configuration, or should I use the terms "dependency injection". This is where the power of Mouf comes particularly handy: this tool, featuring present library, will allow you to create your data parsers/validators with only drag/drop/naming action, occasionally writing little pieces of code (if you wish to implement your own atomic parsers or validators), but without duplication.

How does it work?
-----------------

[](#how-does-it-work)

### Data parsing

[](#data-parsing)

Class `MetaHydrator` uses instances of `HydratingHandlerInterface` to parse and validate raw input. Such an instance should parse specific key(s) in input array (using a configured instance of `ParserInterface`), and may throw an exception (`Invalid`). In `SimpleHydratingHandler` implementation of `HydratingHandlerInterface`, one specific key in input array data is handled, ie the value located at that key is parsed and, if parsing was successful, parsed value is validated. Keep in mind that this validation should not consider other parsed values, since a handler does not wait for all values to be parsed before checking for its handled value sanity.

### Data validation

[](#data-validation)

An implementation of interface `ValidatorInterface` must implement method `validate`; this method will do nothing if input data is correct, and shall throw a `InvalidValueException` if it is not. Such an exception needs an `innerErrorsMap` when constructed. A well-formed errors map should be an associative array, keys being strings, and values each being either a descriptor of the field error (such as a `DetailedErrorMessage`, for instance) or a well-formed errors map. More precisely, its structure should be consistent with input data, where invalid fields would be replaced by those error descriptors.

### Applying parsed data

[](#applying-parsed-data)

Using an inner simple hydrator (by default, TDBMHydrator seems to be a good choice), the parsed data can finally be used in two different ways: You can whether apply it to an already existing object, (using implementation of method `hydrateObject`) of your hydrator, or create a new instance of the class you wish to instanciate (method `hydrateNewObject`).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.8% 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

Unknown

Total

1

Last Release

2793d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

validationhydratorparsingmouf

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k510.9M901](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k156.0M488](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.0M408](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k38.3M139](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65141.2M263](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9315.3M63](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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