inovia-team/matters-repository

There is no license information available for the latest version (1.1.2) of this package.

Matters' proposal on how to use zendframework/zend-db

1.1.2 2018-05-18 16:30 UTC

This package is not auto-updated.

Last update: 2024-03-17 02:09:56 UTC


README

Matters proposal usage of zend-repository

Usage

Definition of a \Matters\Repository

<?php
    class TableRepository extends \Matters\Repository {

        public function findAllByName(string $name)
        {
            $select = $this->select();
            $select->where
                ->equalTo([
                    'name'       => $name,
                ]);

            $select->order(['created_at' => 'DESC']);

            return $this->fetchListEntities($select);
        }
    }

Instanciation

<?php
    $hydratingResultSet = new \Zend\Db\ResultSet\HydratingResultSet(
        new Hydrator(),
        new Model()
    );

    $tableGateway = new \Zend\Db\TableGateway\TableGateway(
        'table_name',
        new \Zend\Db\Adapter\Adapter($config),
        null,
        $hydratingResultSet
    );

    $tableRepository = new TableRepository($tableGateway);
    $entities = $tableRepository->findAllByName('Bob');    

Tests

./vendor/bin/phpunit tests