PHPackages                             stratadox/hydrate - 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. [Database &amp; ORM](/categories/database)
4. /
5. stratadox/hydrate

ActiveLibrary[Database &amp; ORM](/categories/database)

stratadox/hydrate
=================

v0.2(8y ago)18MITPHPPHP &gt;=7.1

Since Nov 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Stratadox/Hydrate)[ Packagist](https://packagist.org/packages/stratadox/hydrate)[ RSS](/packages/stratadox-hydrate/feed)WikiDiscussions master Synced yesterday

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

Hydrate
=======

[](#hydrate)

[![Build Status](https://camo.githubusercontent.com/fe5e9e2d57c5047fac3e9df15bc9c1d3c5ccbc2ee07ee43b0c7840ee3f31d017/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f487964726174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/Hydrate)

The `Hydrate` module contains all that is needed to hydrate objects from arbitrary data. This data could come from a sql database, a document store, a web API or any other source.

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

[](#installation)

Install using composer:

`composer require stratadox/hydrate`

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

[](#basic-usage)

1. Use the Mapper to create a hydrator that can can build your domain model from the input data:

```
$hydrator = Mapper::forThe(Book::class)
   ->property('title', Has::one(Title::class)->with('title'))
   ->property('isbn', Has::one(Isbn::class)->with('code', In::key('id'))
   ->property('author', Has::one(Author::class)
       ->with('firstName', In::key('author_first_name'))
       ->with('lastName', In::key('author_last_name'))
   )
   ->property('contents')
   ->hydrator();
```

2. Load the data from the data source:

```
$books = [];
$result = $database->query("SELECT * FROM `book`");
while ($data = $result->row) {
    $books[] = $hydrator->fromArray($data);
}
```

3. All done! Your objects, in this case a bunch of books, are now hydrated as fully fledged object graphs, each containing their related objects, like a Title, an Isbn and an Author.

In fact, the above mapping would transform a query result like this:

```
+------------+---------------+-------------------+------------------+----------------------------+
| id         | title         | author_first_name | author_last_name | contents                   |
+------------+---------------+-------------------+------------------+----------------------------+
| 1234567890 | Book Title    | John              | Doe              | Lorem ipsum dolor sit amed |
| 9876543210 | Foo, bar, baz | Jackie            | Chan             | Lorem ipsum dolor sit amed |
+------------+---------------+-------------------+------------------+----------------------------+

```

...into an object structure like this:

```
array(2) {
  [0] => object(Book)#1 (4) {
    ["title"] => object(Title)#2 (1) {
      ["title"] => string(10) "Book Title"
    }
    ["isbn"] => object(Isbn)#3 (1) {
      ["code"] => string(10) "1234567890"
    }
    ["author"] => object(Author)#4 (2) {
      ["firstName"] => string(4) "John"
      ["lastName"] => string(3) "Doe"
    }
    ["contents"] => string(26) "Lorem ipsum dolor sit amed"
  }
  [1] => object(Book)#1 (4) {
    ["title"] => object(Title)#2 (1) {
      ["title"] => string(10) "Foo, bar, baz"
    }
    ["isbn"] => object(Isbn)#3 (1) {
      ["code"] => string(10) "9876543210"
    }
    ["author"] => object(Author)#4 (2) {
      ["firstName"] => string(4) "Jackie"
      ["lastName"] => string(3) "Chan"
    }
    ["contents"] => string(26) "Lorem ipsum dolor sit amed"
  }
}

```

Features
--------

[](#features)

The example above is only the top of the iceberg of possibilities. The `Hydrate`package provides great (and often unique) features, such as:

- Producing value objects using multiple keys of the result set
- Lazy (and extra lazy) loading relationships, even if they're in arrays or immutable collections!
- Deciding on a concrete implementation at runtime ("single table inheritance")
- Complete control over data interpretation by calling a Closure to load the property value.
- [...and more!](documentation/README.md)

Subpackages
-----------

[](#subpackages)

The `Hydrate` package contains no source code (save some integration tests) Instead it composes several sub-packages. These packages are listed below.

### Hydrator

[](#hydrator)

Produces objects, complete with data in their properties, without calling constructor functions.

[![Source Code](https://camo.githubusercontent.com/1b8438d45d6591c1b9492f8056dc5881523621380da69c0a1f0f113328f07aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6769746875622d626c75652e737667)](https://github.com/Stratadox/Hydrator)[![Implements](https://camo.githubusercontent.com/6bcfbb03d5cf753c1c7d010fc4cab923b88b7231cb9e7827e40176c4c5787637/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e74657266616365732d6769746875622d626c75652e737667)](https://github.com/Stratadox/HydratorContracts)[![Build Status](https://camo.githubusercontent.com/bb863a793c53557ebc43b358c152fc2710a6fc41c6e03305bb7321a62338df83/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f4879647261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/Hydrator)[![Coverage Status](https://camo.githubusercontent.com/7fb02d197efdc20997bdfa1e999c8ae0f52dec3a9963ac6288102891c6e253bc/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f4879647261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/Hydrator?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/211f01721881185ecfc51972a3bbf406e07167402d0d1e1657f9a08ec353aa52/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f4879647261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/Hydrator/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/1b19bcb0dda447760f2f2f6452ee949b26d7355ee194e1833f26cb51da307e02/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f6879647261746f722f762f737461626c65)](https://packagist.org/packages/stratadox/hydrator)[![License](https://camo.githubusercontent.com/bcdd833f99d75f9c22ec5f722d2588702be2f6d050c6ef654fd8f9e3d0487274/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f6879647261746f722f6c6963656e7365)](https://packagist.org/packages/stratadox/hydrator)

### Hydration mapping

[](#hydration-mapping)

Provides instructions to the hydrators on how to map the input data to the object properties.

[![Source Code](https://camo.githubusercontent.com/1b8438d45d6591c1b9492f8056dc5881523621380da69c0a1f0f113328f07aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6769746875622d626c75652e737667)](https://github.com/Stratadox/HydrationMapping)[![Implements](https://camo.githubusercontent.com/6bcfbb03d5cf753c1c7d010fc4cab923b88b7231cb9e7827e40176c4c5787637/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e74657266616365732d6769746875622d626c75652e737667)](https://github.com/Stratadox/HydrationMappingContracts)[![Build Status](https://camo.githubusercontent.com/3c74bdc417bb47141dab6446c08da0964a890eb4c234c68a3b90b3cc936ee0fb/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f487964726174696f6e4d617070696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/HydrationMapping)[![Coverage Status](https://camo.githubusercontent.com/7778ae8a7fc1b2feaca8501dfaea64a5f78a8204a059c2aed86766eb8c42eb30/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f487964726174696f6e4d617070696e672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/HydrationMapping?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6ed0118ad41bb0c110b7c1a9b98dc70c6e1c092704d89dd762977d0d55696b62/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f487964726174696f6e4d617070696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/HydrationMapping/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/af961420186d2a3ca16bd34cb5f15340dee0237ee9bf2d4f112516e4af7723d3/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f687964726174696f6e2d6d617070696e672f762f737461626c65)](https://packagist.org/packages/stratadox/hydration-mapping)[![License](https://camo.githubusercontent.com/72c1beb71a730780c108a82b588f76a32d382a371e74381627564dadb59f1cd1/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f687964726174696f6e2d6d617070696e672f6c6963656e7365)](https://packagist.org/packages/stratadox/hydration-mapping)

### Proxy

[](#proxy)

Provides proxy functionality for lazy loading of objects whose data is not loaded into the system yet.

[![Source Code](https://camo.githubusercontent.com/1b8438d45d6591c1b9492f8056dc5881523621380da69c0a1f0f113328f07aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6769746875622d626c75652e737667)](https://github.com/Stratadox/Proxy)[![Implements](https://camo.githubusercontent.com/6bcfbb03d5cf753c1c7d010fc4cab923b88b7231cb9e7827e40176c4c5787637/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e74657266616365732d6769746875622d626c75652e737667)](https://github.com/Stratadox/ProxyContracts)[![Build Status](https://camo.githubusercontent.com/b23773dd6cd8de6121408f149f35afff83ee085c47706956ca3b2975a973e9c3/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f50726f78792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/Proxy)[![Coverage Status](https://camo.githubusercontent.com/0bbff2755eaab666738b8fe079ab54e7d34be61521f59b9425a1a2517a924f51/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f50726f78792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/Proxy?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d69947cad0d111e977aec24b10d62f546e685b524daf25b4d930a0d1ebbad76d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f50726f78792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/Proxy/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/cd3f214a0929ef9d043d97e85d002421d85c4c007110f927d6760d1d013cf756/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792f762f737461626c65)](https://packagist.org/packages/stratadox/proxy)[![License](https://camo.githubusercontent.com/a3b23b37a5701c61824208e777f11f79e5c144183affbf8dd34009e996162cea/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792f6c6963656e7365)](https://packagist.org/packages/stratadox/proxy)

### Hydration mapper

[](#hydration-mapper)

Tools to ease the construction of hydration maps.

[![Source Code](https://camo.githubusercontent.com/1b8438d45d6591c1b9492f8056dc5881523621380da69c0a1f0f113328f07aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6769746875622d626c75652e737667)](https://github.com/Stratadox/HydrationMapper)[![Implements](https://camo.githubusercontent.com/6bcfbb03d5cf753c1c7d010fc4cab923b88b7231cb9e7827e40176c4c5787637/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e74657266616365732d6769746875622d626c75652e737667)](https://github.com/Stratadox/HydrationMapperContracts)[![Build Status](https://camo.githubusercontent.com/7d7b3f20c3dd2af09a5db7fcc99d54b0683afb8632d43dd67a9c646eaa5726ab/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f487964726174696f6e4d61707065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/HydrationMapper)[![Coverage Status](https://camo.githubusercontent.com/080798bf9b9599fded89b5b254e402713fd365b77969fe154d692f066619b05b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f487964726174696f6e4d61707065722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/HydrationMapper?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/64717b81bbc1cc11c0ed68b3279355930ac7689f137da12db0e4571e7abc917e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f487964726174696f6e4d61707065722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/HydrationMapper/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/95188410b666bae9751c3334e8704df68ad9e2e404f9cfa160ec18ee72e2a0f1/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f687964726174696f6e2d6d61707065722f762f737461626c65)](https://packagist.org/packages/stratadox/hydration-mapper)[![License](https://camo.githubusercontent.com/ea098899abac6676e0e52eae3f44096a0bdad08a714f35b4d32adfd639b210c7/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f687964726174696f6e2d6d61707065722f6c6963656e7365)](https://packagist.org/packages/stratadox/hydration-mapper)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Total

2

Last Release

3081d ago

### Community

Maintainers

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

---

Top Contributors

[![Stratadox](https://avatars.githubusercontent.com/u/5333260?v=4)](https://github.com/Stratadox "Stratadox (60 commits)")

---

Tags

hydratehydrationhydratorlazy-loadingmappermappingmappingsormphp7proxiesproxy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stratadox-hydrate/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198628.3k10](/packages/pgvector-pgvector)

PHPackages © 2026

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