martinezdelariva/hydrator
最新稳定版本:v1.0
Composer 安装命令:
composer require martinezdelariva/hydrator
包简介
Hydrate and extract functions made simple. Ideally for flat or primitive data.
README 文档
README
Hydrator
Hydrate and extract functions made simple. Ideally for flat objects or primitive data.
Installation
Install it using Composer
composer require martinezdelariva/hydrator
Usage
Having the following class:
class Person { private $name; private $age; private $hobbies = []; private $student = false; public function __construct(string $name, int $age, array $hobbies, bool $student) { $this->name = $name; $this->age = $age; $this->hobbies = $hobbies; $this->student = $student; } }
Extraction:
use function Martinezdelariva\Hydrator\extract; $person = new Person("John", 29, ["soccer", "reading"], true); extract($person); // array ( // 'name' => 'John', // 'age' => 29, // 'hobbies' => array ( // 0 => 'soccer', // 1 => 'reading', // ), // 'student' => true, // )
Hydration:
use function Martinezdelariva\Hydrator\hydrate; $values = [ "name" => "Maria", "age" => 30, "hobbies" => ["swimming", "coding"], ]; $person = hydrate(Person::class, $values); // object(Person)#48 (4) { // ["name":"Person":private] => string(5) "Maria" // ["age":"Person":private] => int(30) // ["hobbies":Person":private]=> // array(2) { // [0]=> // string(8) "swimming" // [1]=> // string(6) "coding" // } // ["student":"Person":private] => bool(false)
统计信息
- 总下载量: 22.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-29