PHP code example of helicon / object-mapper
1. Go to this page and download the library: Download helicon/object-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/ */
helicon / object-mapper example snippets
// ./example.php
declare(strict_types=1);
on\ObjectMapper\Tests\Friend;
class Friend
{
private int $id;
private string $name;
private \DateTime $createdAt;
private self $child;
}
$data = [
'id' => '1',
'name' => 'polidog',
'createdAt' => date('Y-m-d H:i:s'),
'child' => [
'id' => '3',
'name' => 'yamada',
'createdAt' => date('Y-m-d H:i:s'),
],
];
// Factory object mapper
$mapper = (new ObjectMapperFactory())();
$object = ($mapper)($data, Friend::class)
var_dump($object); // Friend object.