Skip to content

codisart/storal-repository

Repository files navigation

storal-repository

Build Status Maintainability Test Coverage

A proposal on how to use laminas/laminas-db

Usage

Definition of a \Storal\Repository

<?php
    class TableRepository extends \Storal\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 \Laminas\Db\ResultSet\HydratingResultSet(
        new Hydrator(),
        new Model()
    );

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

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

Exists

<?php
    class TableRepository extends \Storal\Repository {

        public function wasCooked()
        {
            $select = $this->exists();
            $select->where->equalTo('is_cooked', true);
            return $this->fetchExists($select);
        }
    }

Tests

./vendor/bin/phpunit