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

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

jameshalsall/object-hydrator
============================

A simple object hydrator using reflection for constructor or setter based injection.

1.2.0(9y ago)33.5k1[1 issues](https://github.com/jameshalsall/object-hydrator/issues)2MITPHPPHP &gt;=5.4

Since Nov 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jameshalsall/object-hydrator)[ Packagist](https://packagist.org/packages/jameshalsall/object-hydrator)[ RSS](/packages/jameshalsall-object-hydrator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (11)Used By (2)

Object Hydrator
===============

[](#object-hydrator)

[![Build Status](https://camo.githubusercontent.com/fdd1fa2a5aa62e9701212847f21ece6641a3153b7e384f4336259cea4aa34f49/68747470733a2f2f7472617669732d63692e6f72672f6a616d657368616c73616c6c2f6f626a6563742d6879647261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jameshalsall/object-hydrator)

A *simple* object hydrator using reflection for constructor or setter based injection.

The hydrator takes an array of raw data and hydrates one or multiple objects of a given class with that data.

Usage
-----

[](#usage)

There are two main types of hydrator provided, the `ObjectConstructorFromArrayHydrator` and the `ObjectSetterFromArrayHydrator` allowing you to hydrate via a constructor or via setters, respectively.

### Constructor hydration

[](#constructor-hydration)

If your object uses constructor injection then you can hydrate your objects using an instance of `ObjectConstructorFromArrayHydrator`.

Example:

```
$data = ['name' => 'Frank Turner', 'job_title' => 'Musician'];
$hyrdator = new ObjectConstructorFromArrayHydrator();
$person = $hydrator->hydrate('Person\Employee', $data);
```

The `Person\Employee` class would look as follows:

```
