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

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

ngexp/hydrator
==============

Hydration and validation of data to a pre-defined class structure controlled by php 8 attributes

1.1.1(3y ago)19MITPHPPHP &gt;=8.1

Since Jun 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ngexp/hydrator)[ Packagist](https://packagist.org/packages/ngexp/hydrator)[ Docs](https://github.com/ngexp/hydrator)[ RSS](/packages/ngexp-hydrator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

[![PHPstan](https://camo.githubusercontent.com/1bc07920f0d36e55c17e1d38b1caa132cc605f51a82b388c962870b9a747b898/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e737667)](https://phpstan.org/)[![PHP Composer](https://github.com/ngexp/hydrator/actions/workflows/php.yml/badge.svg)](https://github.com/ngexp/hydrator/actions/workflows/php.yml)

Ngexp/hydrator
==============

[](#ngexphydrator)

Overview
--------

[](#overview)

Ngexp/hydrator is a library that allows you to hydrate data into an object. Hydration is the process of populating an object with data from a source such as an array or JSON. The library makes use of attributes to add additional behavior to the process, such as converting data from one type to another, validating data, and more.

The library requires PHP 8.1 or higher and supports strict type checking while still allowing mixed data types. Some of its features include:

✅ Various attributes for modifying and validating data
✅ Reusable hydration using memoized reflection for improved speed
✅ Extendable with new attributes and adapters for hydration data
✅ Ability to hydrate to any depth
✅ Modifiable error messages
✅ Easy to create custom attributes

---

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Attribute Order Matter](#attribute-order-matter)
- [The constructor is not invoked](#the-constructor-is-not-invoked)
- [Attributes](#attributes)
- [Hydrating from Different Sources](#hydrating-from-different-sources)

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

[](#installation)

To install the latest version of the library, run the following command:

```
composer require ngexp/hydrator

```

Basic Usage
-----------

[](#basic-usage)

Here's an example of how to use the library to hydrate a class:

```
