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-09-14 19:04:13 UTC
README
安装
将 kokoroe/mapper
添加到您的 composer.json
% php composer.phar require kokoroe/mapper:~1.0
用法
<?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);
许可证
mapper-php 在 MIT 许可证 下授权。