2017 © Pedro Peláez
 

library 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.

image

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.

  • Monday, March 16, 2015
  • by manuakasam
  • Repository
  • 3 Watchers
  • 6 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Additional Hydrator Components

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

SensioLabsInsight Scrutinizer Code Quality Build Status Coverage Status, (*2)

Installation

Installation is best done using composr, (*3)

composer require manuakasam/join-hydrator

If asked for a version choose dev-master, (*4)

Usage examples

The usage can easily be checked within the /test folder. But here they are again:, (*5)

Standalone Usage, (*6)

<?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, (*7)

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()
}

The Versions

16/03 2015

dev-master

9999999-dev https://samminds.com

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.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 hydrator zend-db join zend-stdlib join-hydrator tablegateway