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

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

scn/hydrator
============

A pragmatic hydrator and extractor library

3.0.0(5y ago)2300.1k↓33.7%2MITPHPPHP ^7.4|^8.0CI failing

Since Jul 20Pushed 4y ago3 watchersCompare

[ Source](https://github.com/SC-Networks/Hydrator)[ Packagist](https://packagist.org/packages/scn/hydrator)[ RSS](/packages/scn-hydrator/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (2)Versions (10)Used By (2)

scn/hydrator
============

[](#scnhydrator)

[![Latest Stable Version](https://camo.githubusercontent.com/d43003676d51b1b445da1480886aef6ee53a87c9ba496df52b98c2635e14c898/68747470733a2f2f706f7365722e707567782e6f72672f73636e2f6879647261746f722f762f737461626c65)](https://packagist.org/packages/scn/hydrator)[![Monthly Downloads](https://camo.githubusercontent.com/06ba9694ff2f9268c6d91a0835c91c3f7b913d4337a6e7751bb9dd24c9e0bbf3/68747470733a2f2f706f7365722e707567782e6f72672f73636e2f6879647261746f722f642f6d6f6e74686c79)](https://packagist.org/packages/scn/hydrator)[![License](https://camo.githubusercontent.com/6b786c75b2f2a7268f0b115899782d2f802ecf2ebe02dca5d92d88e7fe15cb9a/68747470733a2f2f706f7365722e707567782e6f72672f73636e2f6879647261746f722f6c6963656e7365)](LICENSE)

A pragmatic hydrator and extractor library
------------------------------------------

[](#a-pragmatic-hydrator-and-extractor-library)

### Installation

[](#installation)

Via Composer:

```
$ composer require scn/hydrator

```

### Usage

[](#usage)

See the `examples` folder for usage instructions by code.

#### Extraction

[](#extraction)

First of all you'll need a class that implements `\Scn\Hydrator\Config\ExtractorConfigInterface`. The only method `getExtractorProperties` has to return an array with string keys and callables as values.

The string keys of this array are used to craft the result of the extraction.

The corresponding callables must have the signature `callable(string $propertyName): mixed`. The `$propertyName`parameter will be the corresponding string key. You will usually not need this information.

If this callable is an instance of `\Closure`, its' `$this` and `static` context are bound to the entity object to extract. As a result of this the closure will have access to private and protected properties and methods of the entity.

A short example:

```
