kevbradwick/drift
Composer 安装命令:
composer require kevbradwick/drift
包简介
A lightweight PHP library for mapping data to PHP classes
关键字:
README 文档
README
Drift is a PHP library for mapping arbitrary data to PHP classes.
Installation
Drift is available on Packagist, so you can use composer;
composer require kevbradwick/drift
Usage
Say you have a class with private member variables like this;
namespace Application; class Actor { /** * @Drift\String() */ private $name; /** * @Drift\Int() */ private $age; /** * @Drift\Date(field="date_of_birth") */ private $dateOfBirth; }
And you have some data, possibly consumed from an API, that looks like this;
$data = [ 'name' => 'Arnold Schwarzenegger', 'age' => 68, 'date_of_birth' => 'July 30, 1947' ]
You can then use Drift\Mapper to create a new instance of the class,
initialised with the data.
use Drift\Mapper; use Drift\Reader\AnnotationReader; use Application\Actor; $mapper = new Mapper(new AnnotationReader()); $mapper->setData($data); $actor = $mapper->instantiate(Actor::class);
In addition to annotations, you can specify mapping using Yaml or plain old php.
Full documentation can be found on the Wiki.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-19