helicon / object-mapper
Simple object mapping.
Installs: 1 155
Dependents: 1
Suggesters: 0
Security: 0
Stars: 19
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- helicon/type-converter: ^1.1
- laminas/laminas-hydrator: ^4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- phpunit/phpunit: ^9.5
README
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.