PHP code example of power-data-hub / metamorphose

1. Go to this page and download the library: Download power-data-hub/metamorphose library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

power-data-hub / metamorphose example snippets


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']

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]

use \PowerDataHub\Metamorphose\Transformers\TrimTransformer;

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

// Output

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