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

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

solbianca/hydrator
==================

Hydrate objects from an array and extracting data from objects.

v1.0.0(8y ago)07MITPHPPHP &gt;=7.0

Since Jan 20Pushed 8y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Hydrator
========

[](#hydrator)

[![Build Status](https://camo.githubusercontent.com/fbb8532c6728100a9701b9467c13b667416da93c88da29349f0cdee53c732720/68747470733a2f2f7472617669732d63692e6f72672f736f6c6269616e63612f6879647261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/solbianca/hydrator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/428f78638587684adf550723d3b9c8a7edbe9ba965fc0dc4f85282322c729d4f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6c6269616e63612f6879647261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/solbianca/hydrator/?branch=master)

Hydrator can be used for two purposes:

- To extract data from a class.
- To fill an object with data or create a new instance of a class filled with data.

In both cases it is saving and filling protected and private properties without calling any methods which leads to ability to persist state of an object with properly encapsulated data. Any static properties will be ignored.

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

[](#installation)

The preferred way to install this package is through [composer](http://getcomposer.org/download/).

```
composer require --prefer-dist solbianca/hydrator

```

Usage
-----

[](#usage)

Consider we have a `Post` entity which represents a blog post. It has a title and a text. A unique id is generated to identify it.

```
class Post
{
    private $id;
    protected $title;
    protected $text;

    public function __construct($title, $text)
    {
        $this->id = uniqid('post_', true);
        $this->title = $title;
        $this->text = $text;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function getText()
    {
        return $this->text;
    }

    public function setText()
    {
        return $this->text;
    }
}
```

Saving a post to database:

```
$post = new Post('First post', 'Hell, it is a first post.');

$hydrator = new \SolBianca\Hydrator\Hydrator();

$data = $hydrator->extract($post);
save_to_database($data);

  OR

$data = $hydrator->extract($post, ['id', 'title']); // extract id and title form object
save_to_database($data);
```

Loading post from database:

```
$data = load_from_database();

$hydrator = new \SolBianca\Hydrator\Hydrator();

$post = $hydrator->hydrate(Post::class, $data);
echo $post->getId();
```

Filling existing post object with data:

```
$data = load_from_database();

$hydrator = new \SolBianca\Hydrator\Hydrator();

$post = get_post();
$post = $hydrator->hydrate($post, $data);
echo $post->getTitle();
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3084d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f7a490f4573a3a3994e8d8def59ec31ca7201be4e7729b56d9273c93cfddfa2?d=identicon)[solbianca](/maintainers/solbianca)

---

Top Contributors

[![solbianca](https://avatars.githubusercontent.com/u/5719760?v=4)](https://github.com/solbianca "solbianca (10 commits)")

---

Tags

hydratehydratorextract

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k407.7M733](/packages/symfony-var-exporter)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k13.2M168](/packages/cuyz-valinor)[samdark/hydrator

Allows to extract data from an object or create a new object based on data for the purpose of persisting state. Works with private and protected properties.

11478.8k](/packages/samdark-hydrator)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k99](/packages/flow-php-etl)[nojimage/twitter-text-php

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets.

1192.0M7](/packages/nojimage-twitter-text-php)[marquine/php-etl

Extract, Transform and Load data using PHP.

182138.0k](/packages/marquine-php-etl)

PHPackages © 2026

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