kokoroe / mapper
A PHP5.5+ mapper to convert array of data into nested PHP objects
v1.0.3
2016-08-08 08:40 UTC
Requires (Dev)
- leaphub/phpcs-symfony2-standard: 2.0.1
- phpunit/phpunit: ^5.4
- satooshi/php-coveralls: ^1.0
This package is not auto-updated.
Last update: 2024-12-21 20:36:09 UTC
README
Install
Add kokoroe/mapper
to your composer.json
:
% php composer.phar require kokoroe/mapper:~1.0
Usage
<?php require __DIR__ . '/vendor/autoload.php'; class Article { protected $title; protected $content; protected $author; protected $tags = []; public function setTitle($title) { $this->title = $title; } public function setContent($content) { $this->content = $content; } public function setAuthor(User $author) { $this->author = $author; } public function setTags(array $tags) { $this->tags = $tags; } } class User { protected $id; protected $name; public function setId($id) { $this->id = $id; } public function setName($name) { $this->name = $name; } } $article = Mapper::hydrate([ 'title' => 'test', 'content' => 'foo', 'author' => [ 'id' => 1, 'name' => 'Axel' ], 'tags' => ['test', 'mapping'] ], Article::class); var_dump($article);
License
mapper-php is licensed under the MIT license.