helicon/object-mapper

Simple object mapping.

1.1.0 2023-08-22 02:49 UTC

This package is auto-updated.

Last update: 2024-04-22 04:14:48 UTC


README

test

This library is mapping for the array to object. It's very simple.

using

$ composer req helicon/object-mapper
<?php

// ./example.php

declare(strict_types=1);

require __DIR__.'/vendor/autoload.php';


use Helicon\ObjectMapper\ObjectMapper;
use Helicon\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.