clean / repository
Installs: 48 316
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.5.0
Requires (Dev)
- aura/sql: 2.5.0
- aura/sqlquery: 2.6.0
- clean/data: 2.2.0
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.2.*
- romannowicki/mpr: dev-master
- sobstel/metaphore: 1.2.*
README
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.
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:
"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.:
/* 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:
- when you need to reduce result use
filter...
, oronly...
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