定制 odan/hydrator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

odan/hydrator

最新稳定版本:1.4.1

Composer 安装命令:

composer require odan/hydrator

包简介

A high performance hydrator for PHP.

README 文档

README

A high performance hydrator for PHP.

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Requirements

  • PHP >= 7.1

Installation

composer require odan/hydrator

Features

  • Array to Object
  • Object to Array

ObjectProperty

Any data key matching a publicly accessible property will be hydrated; any public properties will be used for extraction.

ClassMethod

Any data key matching a setter method will be called in order to hydrate; any method matching a getter method will be called for extraction.

Usage

// User entity
class User
{
    public $id;
    public $username;
    public $firstName;
    public $email;
}

// A row from the database
$userRow = [
    'id' => 1,
    'username' => 'admin',
    'first_name' => 'John Doe',
    'email' => 'john@example.com'
];

// Create the hydrator
$hydrator = new \Odan\Hydrator\ObjectProperty();

// Convert array to a new User object (with lower camel case properties)
$user = $hydrator->hydrate($userRow, new User());

print_r($user);

/*
User Object
(
    [id] => 1
    [username] => admin
    [firstName] => John Doe
    [email] => john@example.com
)
*/

// Convert User object to an array with lower camel case keys
$array = $hydrator->extract($user);

print_r($array);

/*
Array
(
    [id] => 1
    [username] => admin
    [first_name] => John Doe
    [email] => john@example.com
)
*/

Alternatives

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 18.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-04