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

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

api-clients/hydrator
====================

Hydrator wrapping ocramius/generated-hydrator specifically for api clients

1.1.1(5y ago)495.6k↓45.3%1[1 issues](https://github.com/php-api-clients/hydrator/issues)[6 PRs](https://github.com/php-api-clients/hydrator/pulls)4MITPHPPHP ^7.3

Since Oct 12Pushed 2y ago3 watchersCompare

[ Source](https://github.com/php-api-clients/hydrator)[ Packagist](https://packagist.org/packages/api-clients/hydrator)[ RSS](/packages/api-clients-hydrator/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (10)Versions (16)Used By (4)

Hydrator for API Clients for PHP 7.x
====================================

[](#hydrator-for-api-clients-for-php-7x)

[![License](https://camo.githubusercontent.com/5851945c08a912a7e94716160357ce08284247acadea274b3f64c3a393fae37a/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6879647261746f722f6c6963656e73652e706e67)](https://packagist.org/packages/api-clients/hydrator)[![Linux Build](https://camo.githubusercontent.com/edc650b049fe0a591bb6a265e277fc50ec8cfd80a6fe6f7187d6c4aef62ebe06/68747470733a2f2f626c6f672e77797269686178696d75732e6e65742f696d616765732f6c696e75782d6c6f676f2d69636f6e2d32302e706e67)](https://camo.githubusercontent.com/edc650b049fe0a591bb6a265e277fc50ec8cfd80a6fe6f7187d6c4aef62ebe06/68747470733a2f2f626c6f672e77797269686178696d75732e6e65742f696d616765732f6c696e75782d6c6f676f2d69636f6e2d32302e706e67)[![Build Status](https://camo.githubusercontent.com/c224abf8afb56a4f353ab08d63b2a6efbaeba8f0e8f9fc04634ef00d0afa8b8d/68747470733a2f2f7472617669732d63692e6f72672f7068702d6170692d636c69656e74732f6879647261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-api-clients/hydrator)[![Windows Build](https://camo.githubusercontent.com/6866bbcbd4c1df9608aabb3e614565325afd15bf685b879db13aeb37cd7b0c4e/68747470733a2f2f626c6f672e77797269686178696d75732e6e65742f696d616765732f77696e646f77732d6c6f676f2d69636f6e2d32302e706e67)](https://camo.githubusercontent.com/6866bbcbd4c1df9608aabb3e614565325afd15bf685b879db13aeb37cd7b0c4e/68747470733a2f2f626c6f672e77797269686178696d75732e6e65742f696d616765732f77696e646f77732d6c6f676f2d69636f6e2d32302e706e67)[![Build status](https://camo.githubusercontent.com/edc022833c63656522ad9c22ff058795e0b98be7f5e76c0dafa220f6c3dc1fc7/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6a7031686d6e347772636a6e6e77706c3f7376673d74727565)](https://ci.appveyor.com/project/WyriHaximus/hydrator)[![Code Coverage](https://camo.githubusercontent.com/24b0682617e58910c23398d600e2faadf1a22e199448640008d75714a0b88698/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d6170692d636c69656e74732f6879647261746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-api-clients/hydrator/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/79d65d185d3bf941a56d4c009556eaffd2b46d7f8964102ae62c91c9e88d9b02/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6879647261746f722f762f737461626c652e706e67)](https://packagist.org/packages/api-clients/hydrator)[![Total Downloads](https://camo.githubusercontent.com/c272993fb71baba42bb25dcc412fd7cd257bfb637bad9c37e2f9dbf8afd5faba/68747470733a2f2f706f7365722e707567782e6f72672f6170692d636c69656e74732f6879647261746f722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/api-clients/hydrator/stats)[![PHP 7 ready](https://camo.githubusercontent.com/1f08e9c75cd9d80216900f4e0fa170eb60bee1c49df783d7787f8f39f3f0f248/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f7068702d6170692d636c69656e74732f6879647261746f722f62616467652e737667)](https://travis-ci.org/php-api-clients/hydrator)

In a nutshell this package is a wrapper around [`ocramius/generated-hydrator`](https://github.com/Ocramius/GeneratedHydrator) adding some annotations for nesting, collections, and renaming properties.

Install
=======

[](#install)

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.

```
composer require api-clients/hydrator

```

Preheating
==========

[](#preheating)

In order to ensure the hydrator doesn't block the hydrator comes with a `preheat` method. Give it a the path of a namespace and the namespace it self, and it will create a hydrator for each resource it finds plus read the annotations for the given resource. This ensures all disk IO and heavy CPU operations have been completed before using the hydrator. When using the hydrator in async code the hydrator should, preferable, be created before running the loop.

Set up
======

[](#set-up)

Before using the Hydrator it has to be set up, note that using this method of setting up it will also preheat the hydrator.

```
$loop = LoopFactory::create();
$commandBus = new CommandBus(); // Implementation of ApiClients\Tools\CommandBus\CommandBusInterface
$options = []; // Options as described below
$hydrator = Factory::create($loop, $commandBus, $options);
```

Hydrating
=========

[](#hydrating)

The hydrator offers two methods of hydrating. The first is a method that accepts FQCN (Fully Qualified Class Name), for example `ApiClients\Client\Github\Resource\Async\Emoji` or `Emoji::class` for short, and the JSON holding the resource contents.

```
$resource = $hydrator->hydrateFQCN(Emoji::class, $json);
```

Or when you've configured `Options::NAMESPACE`, `Options::NAMESPACE_SUFFIX` you can do the same with the `hydrate` method, which internally uses `hydrateFQCN`:

```
$resource = $hydrator->hydrate('Emoji', $json);
```

Extracting
==========

[](#extracting)

A resource can also be broken down again into JSON with the hydrator.

```
$json = $hydrator->extractFQCN(Emoji::class, $resource);
```

Same magic as the `hydrate` method applies to the `extract` method, this does exactly the same as `extractFQCN` when `Options::NAMESPACE` and `Options::NAMESPACE_SUFFIX` are configured.

```
$json = $hydrator->extract('Emoji', $resource);
```

Options
=======

[](#options)

Options::ANNOTATIONS
--------------------

[](#optionsannotations)

Supply an array with extra annotations in the format key =&gt; annotation, value =&gt; handler.

Options::ANNOTATION\_CACHE\_DIR
-------------------------------

[](#optionsannotation_cache_dir)

Cache directory for resource annotations.

Options::NAMESPACE
------------------

[](#optionsnamespace)

Base namespace where the resources reside, required.

Options::NAMESPACE\_DIR
-----------------------

[](#optionsnamespace_dir)

Filesystem path to the base namespace where the resources reside, required.

Options::NAMESPACE\_SUFFIX
--------------------------

[](#optionsnamespace_suffix)

Namespaces suffix, useful for different types of the same resource.

Options::RESOURCE\_CACHE\_DIR
-----------------------------

[](#optionsresource_cache_dir)

Cache directory for resource generated resources.

Options::RESOURCE\_NAMESPACE
----------------------------

[](#optionsresource_namespace)

Namespace for generated resources.

License
=======

[](#license)

The MIT License (MIT)

Copyright (c) 2017 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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

Every ~232 days

Recently: every ~335 days

Total

7

Last Release

1961d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.1.0PHP ^7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (346 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (13 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![mdrost](https://avatars.githubusercontent.com/u/4083346?v=4)](https://github.com/mdrost "mdrost (2 commits)")

---

Tags

hacktoberfesthydratorphpphp7reactphp

### Embed Badge

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

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[akeneo/pim-community-dev

Akeneo PIM, the future of catalog management is open!

1.0k624.1k86](/packages/akeneo-pim-community-dev)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k18](/packages/solspace-craft-freeform)[internal/dload

Downloads binaries.

102212.2k19](/packages/internal-dload)[metamodels/core

MetaModels core

10156.4k68](/packages/metamodels-core)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)

PHPackages © 2026

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