2017 © Pedro Peláez
 

library repository

image

clean/repository

  • Tuesday, August 29, 2017
  • by romannowicki
  • Repository
  • 1 Watchers
  • 5 Stars
  • 16,070 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 10 Versions
  • 12 % Grown

The README.md

Clean\Repository

Build Status Code Climate Test Coverage Issue Count Latest Stable Version Total Downloads License, (*1)

Use a repository to separate the logic that retrieves the data and maps it to the entity model from the business logic that acts on the model. The business logic should be agnostic to the type of data that comprises the data source layer. For example, the data source layer can be a database or a Web service., (*2)

Objectives

  • You access the data source from many locations and want to apply centrally managed, consistent access rules and logic.
  • You want to implement and centralize a caching strategy for the data source.
  • You want to improve the code's maintainability and readability by separating business logic from data or service access logic.

Installation

via Composer:, (*3)

"require": {
  "clean/repository": "dev-master"
}

Idea and Implementation

Repository is and object that holds multiply criterias. Those criteria can represent query to database or GET request parameters or anything else that require creating some kind of request based on various parameters. The idea is to hide concrate implementation of generating queries or requests behind semantic layer e.g.:, (*4)

/*
   get 
   4 'toyota' cars,
   not older than 10 year,
   only with diesel engine,
   with information about last 2 owners,
   include pictures of car
*/
$carRepository
    ->limit(4)
    ->filterByMark('toyota')
    ->notOlderThan(10)
    ->onlyDiesel()
    ->includeOwners([
        'getLatest' => 2,
    ])
    ->includePictures()
    ->assemble();

There are few rules worth to follow:, (*5)

  • when you need to reduce result use filter..., or only... method
  • when you need to sort result use sortBy... method
  • when you need to extend result use with... method
  • when you need to include related entity use include... method
  • you can also define your own rules valid for your project like notOlderThan

Working example:

The Versions

09/12 2015

2.0.1

2.0.1.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern

10/11 2015

2.0.0

2.0.0.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern

01/09 2015

1.1.0

1.1.0.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern

23/08 2015

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern

05/08 2015

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern

05/08 2015

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

repository pattern