承接 aaronbullard/firehose 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aaronbullard/firehose

Composer 安装命令:

composer require aaronbullard/firehose

包简介

README 文档

README

Maintainability Test Coverage

PHP Reflection Class helper to Instantiate, Mutate, and Extract data directly within a class.

Installation

Library

git clone git@github.com:aaronbullard/firehose.git

Composer

Install PHP Composer

composer require aaronbullard/firehose

Testing

composer test

Usage

Firehose/Hydrator uses PHP reflection to bypass protected and private attribute constraints.

This can be useful when trying to instantiate objects from a database query using a mapper pattern. This method also allows you to bypass any validation constraints within the constructor.

When trying to persist the object, anemic getters are unnecessary. Instance properties can be exctracted as key/value pairs for database persistence.

Examples

Given Foo

class Foo
{
    private $bar;
    protected $baz;
    private $qux;

    public function __construct($bar, $baz = null, $qux = null)
    {
        $this->bar = $bar;
        $this->baz = $baz;
        $this->qux = $qux;
    }

    public function bar(){ return $this->bar; }
    public function baz(){ return $this->baz; }
}

Create a new instance

use Firehose\Hydrator;

$foo = Hydrator::newInstance(Foo::class, [
    'bar' => 'bar',
    'baz' => 'baz'
]);

$this->assertInstanceOf(Foo::class, $foo);
$this->assertEquals('bar', $foo->bar());
$this->assertEquals('baz', $foo->baz());

Mutating a live instance

$foo = new Foo('bar', 'baz');

Hydrator::mutate($foo, [
    'bar' => 'newBar'
]);

$this->assertEquals('newBar', $foo->bar());

Extracting data

$foo = new Foo('bar', 'baz', 'qux');

$data = Hydrator::extract($foo, ['bar', 'baz', 'qux']);

$this->assertEquals('bar', $data['bar']);
$this->assertEquals('baz', $data['baz']);
$this->assertEquals('qux', $data['qux']);

For more examples, see the tests: tests\HydratorTest.php

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固