manuakasam/join-hydrator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

manuakasam/join-hydrator

Composer 安装命令:

composer require manuakasam/join-hydrator

包简介

A set of two very lightweight hydrator components. The main usage of those hydrators would be to hydrate query results from joined tables into their respective nested objects.

README 文档

README

A set of two very simple hydrator helpers to easily hydrate joined query results into their respective nested objects.

SensioLabsInsight Scrutinizer Code Quality Build Status Coverage Status

Installation

Installation is best done using composr

composer require manuakasam/join-hydrator

If asked for a version choose dev-master

Usage examples

The usage can easily be checked within the /test folder. But here they are again:

Standalone Usage

<?php
namespace Test {
    use Sam\Hydrator\AggregateHydrator;
    use Sam\Hydrator\OneToOneHydrator;
    
    $data = [
        'foo_one' => 'TEST FOO ONE',
        'foo_two' => 'TEST FOO TWO',
        'bar_one' => 'BAR FIGHT ONE',
        'bar_two' => 'BAR FIGHT TWO',
        'baz'     => 'LONELY BAZ'
    ];
    
    $aggregateHydrator = new AggregateHydrator(
        new ClassMethods(),
        new OneToOneHydrator('foo_', 'setFoo', new Foo()),
        new OneToOneHydrator('bar_', 'setBar', new Bar())
    );
    
    $dummy = $aggregateHydrator->hydrate($data, new Dummy());
    
    get_class($dummy);           // instanceof Dummy
    get_class($dummy->getFoo()); // instanceof Foo()
    get_class($dummy->getBar()); // instanceof Bar()
}

Usage with Zend\Db\TableGateway

namespace Test {
    use Zend\Db\Adapter\Adapter;
    use Zend\Db\ResultSet\HydratingResultSet;
    use Zend\Db\Sql\Select;
    use Zend\Db\TableGateway\TableGateway;
    use Sam\Hydrator\AggregateHydrator;
    use Sam\Hydrator\OneToOneHydrator;

    $adapter = new Adapter([
        'driver'         => 'Pdo',
        'username'       => 'admin',  //edit this
        'password'       => 'admin',  //edit this
        'dsn'            => 'mysql:dbname=someDB;host=localhost',
        'driver_options' => array(
            \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        )
    ]);

    $prototype = new HydratingResultSet(new AggregateHydrator(
        new ClassMethods(),
        new OneToOneHydrator('foo_', 'setFoo', new Foo()),
        new OneToOneHydrator('bar_', 'setBar', new Bar())
    ), new Dummy());
    
    $gateway   = new TableGateway('dummies', $adapter, null, $prototype);

    $resultSet = $gateway->select(function (Select $select) {
        $select->join('foo', 'clients.foo_id = foo.id', [
            'foo_id'   => 'id',
            'foo_bar'  => 'foo_bar',
            'foo_baz'  => 'foo_baz',
        ]);
        $select->join('bar', 'dummies.bar_id = bar.id', [
            'bar_id'   => 'id',
            'bar_bar'  => 'bar_bar',
            'bar_baz'  => 'bar_baz',
        ]);
    });

    $entryOne = $resultSet->current();
    
    get_class($entryOne);           // instanceof Dummy()
    get_class($entryOne->getFoo()); // instanceof Foo()
    get_class($entryOne->getBar()); // instanceof Bar()
}

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-03-16