power-data-hub/metamorphose

v0.2 2018-05-26 01:24 UTC

README

Metamorphose - Transform your data

Build Status StyleCI Latest Stable Version License

Here are a few examples on how you can use the package:

use \PowerDataHub\Metamorphose\Transformers\TrimTransformer;
use \PowerDataHub\Metamorphose\Metamorphose;

$result = app(Metamorphose::class)
    ->from(['name' => ' John Doe ')
    ->through(TrimTransformer::class)
    ->transform();

// Output

['name' => 'John Doe']

You can pass as many transformers as you want:

use \PowerDataHub\Metamorphose\Transformers\TrimTransformer;
use \PowerDataHub\Metamorphose\Transformers\PercentTransformer;
use \PowerDataHub\Metamorphose\Transformers\NumericTransformer;
use \PowerDataHub\Metamorphose\Metamorphose;

app(Metamorphose::class)
    ->from(['name' => ' John Doe ', 'age' => '33', 'score' => '33.987'])
    ->through([
        TrimTransformer::class,
        PercentTransformer::class,        
        NumericTransformer::class,
    ])
    ->transform();
    
//Output

['name' => 'John Doe', 'age' => 33, 'score' => 33.99]

Installation

You can install the package via composer:

composer require power-data-hub/metamorphose

Transformers

Metamorphose come with some useful transformers

Trim

use \PowerDataHub\Metamorphose\Transformers\TrimTransformer;

app(Metamorphose::class)
    ->from(['name' => ' John', 'last_name' => ' Doe '])
    ->through(TrimTransformer::class)
    ->transform();

// Output

['name' => 'John', 'last_name' => 'Doe']

forthebadge