<commit_before>![redbox-logo-klein](https://cloud.githubusercontent.com/assets/121194/18277406/ac4d9868-744e-11e6-8994-86943704d0d4.png)



[![Build Status](https://travis-ci.org/johnnymast/redbox-hydrator.svg?branch=master)](https://travis-ci.org/johnnymast/redbox-hydrator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/?branch=master)
[![PHP 7.1 Ready](https://img.shields.io/badge/HHVM-Ready-green.svg)](http://hhvm.com/)
[![HHVM Ready](https://img.shields.io/badge/PHP 7.1-Ready-green.svg)](http://hhvm.com/)
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Contact author)](https://twitter.com/intent/tweet?text=@mastjohnny)

# Redbox-hydrate
 
Hydrating an object is fancy talk for populating properties on PHP objects. This Hydrator helps you to quickly **hydrate** new class instances and returns the populated result. Please note it does not mether if you have private or protected properties in your class it will take care of that for you. Look in the examples folder for basic [examples](examples).

## Examples 

I have gone to great length to provide a special (read sexy) and tiny API for you. You can use any kind of API style you see fit in your operation for example.
 
### Static class method 

In this example we will hydrate a new instance of class User and return it as $result1 using with with() function.
 
```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 1
 */
$result1 = Hydrator::hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => '<PASSWORD>'
    ]
);
```
## Hydrate function

***Please note:*** the package provides a function called Hydrate. This function is not concealed in any namespace so its globally available when you have the package loaded into your application. If any function in your code already exists the function will not be declared so it will not colide with your code. See [src/helpers/Hydrator.php](https://github.com/johnnymast/redbox-hydrator/blob/master/src/helpers/Hydrator.php) for more information. In this example $result2 will be an instance of class User.
 
```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 2
 */
$result2 = Hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => '<PASSWORD>'
    ]
);
```

## Instantiate a new Hydrator

Plain old PHP, create your instance of the hydrator then call the with( ) method. 

***Please note*** There is something off with this method as if your doing this inside a loop it might consume some memory because of all the instances you create.

```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 3
 */
$hydrator = new Hydrator(new User());
$result3 = $hydrator->with(<commit_msg>Updated example.php<commit_after>![redbox-logo-klein](https://cloud.githubusercontent.com/assets/121194/18277406/ac4d9868-744e-11e6-8994-86943704d0d4.png)



[![Build Status](https://travis-ci.org/johnnymast/redbox-hydrator.svg?branch=master)](https://travis-ci.org/johnnymast/redbox-hydrator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/johnnymast/redbox-hydrator/?branch=master)
[![PHP 7.1 Ready](https://img.shields.io/badge/HHVM-Ready-green.svg)](http://hhvm.com/)
[![HHVM Ready](https://img.shields.io/badge/PHP 7.1-Ready-green.svg)](http://hhvm.com/)
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Contact author)](https://twitter.com/intent/tweet?text=@mastjohnny)

# Redbox-hydrate
 
Hydrating an object is fancy talk for populating properties on PHP objects. This Hydrator helps you to quickly **hydrate** new class instances and returns the populated result. Please note it does not mether if you have private or protected properties in your class it will take care of that for you. Look in the examples folder for basic [examples](examples).

## Examples 

I have gone to great length to provide a special (read sexy) and tiny API for you. You can use any kind of API style you see fit in your operation for example.
 
### Static class method 

In this example we will hydrate a new instance of class User and return it as $result1 using with with() function.
 
```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 1
 */
$result1 = Hydrator::hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => '<PASSWORD>'
    ]
);
```
## Hydrate function

***Please note:*** the package provides a function called Hydrate. This function is not concealed in any namespace so its globally available when you have the package loaded into your application. If any function in your code already exists the function will not be declared so it will not colide with your code. See [src/helpers/Hydrator.php](https://github.com/johnnymast/redbox-hydrator/blob/master/src/helpers/Hydrator.php) for more information. In this example $result2 will be an instance of class User.
 
```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 2
 */
$result2 = Hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => '<PASSWORD>'
    ]
);
```

## Instantiate a new Hydrator

Plain old PHP, create your instance of the hydrator then call the with( ) method. 

***Please note*** There is something off with this method as if your doing this inside a loop it might consume some memory because of all the instances you create. Please dont forget to use the unset function if you are inside any kind of loop.

```php
use Redbox\Hydrate\Hydrator;

/**
 * Method 3
 */
$hydrator = new Hydrator(new User());
$result3 = $hydrator->with(
{'fraction_non_alphanumeric': 0.12999835445120947, 'fraction_numerical': 0.016784597663320716, 'mean_word_length': 4.369257950530035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 24, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2029706', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1910, 'n_words': 590}