PHP code example of biig / optimus

1. Go to this page and download the library: Download biig/optimus 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/ */

    

biig / optimus example snippets



 
namespace Transformer;
 
use Biig\Optimus\AbstractMappingTransformer;
use Symfony\Component\Yaml\Yaml;
 
class MyTransformer extends AbstractMappingTransformer
{
    /**
     * {@inheritdoc}
     */
    protected function transform(array $inputArray)
    {
        $config = Yaml::parseFile('/mapping.yaml');
        $result = $this->transformFromMapping($config['transformer']['mapping'], $inputArray);
        // ...
        return $result;
    }
}

$inputArray = [
    'user' => [
        'civility' => 'M',
        'firstname' => 'John',
        'lastname' => 'Doe',
    ],
    'title' => 'A title',
];

$outputArray = [
    'title' => 'A title',
    'participants' => [
        0 => [
            'civility' => 'M',
            'name' => 'Doe',
        ],
    ],
];

public function getCivility($civility)
{
    $array = [
        'Mr' => 1,
        'Mrs' => 2,
    ];
    
    return $array[$civility];
}