PHP code example of mike-roetgers / data-mapper

1. Go to this page and download the library: Download mike-roetgers/data-mapper 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/ */

    

mike-roetgers / data-mapper example snippets


$data = '{"id": 1, "name": "Mike"}';

$mapper = new GenericMapper(new EntityAutoMapper(), '\\My\\Namespace\\TestEntity');
$entity = $mapper->mapJsonToEntity($data);

echo $entity->getId(); // 1
echo $entity->getName(); // Mike

$data = '{"user_id": 23, "user_name": "Jonathan"}';

$mapper = new GenericMapper(new EntityAutoMapper(), '\\My\\Namespace\\TestEntity', array('id' => 'user_id', 'name' => 'user_name'));
$entity = $mapper->mapJsonToEntity($data);

echo $entity->getId(); // 23
echo $entity->getName(); // Jonathan