PHPackages                             clean/repository - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. clean/repository

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

clean/repository
================

2.0.4(8y ago)748.7k2MITPHPPHP &gt;=5.5.0

Since Aug 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/clean/repository)[ Packagist](https://packagist.org/packages/clean/repository)[ RSS](/packages/clean-repository/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (10)Used By (0)

Clean\\Repository
=================

[](#cleanrepository)

[![Build Status](https://camo.githubusercontent.com/12cb93d146801141b9fdb81211971818722b6632472dc13458fd8ae1767b093f/68747470733a2f2f7472617669732d63692e6f72672f636c65616e2f7265706f7369746f72792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/clean/repository)[![Code Climate](https://camo.githubusercontent.com/1b6fd82a8868c128534a571a397ab0f00f45282a9fdc10f4e01fa1953ea00cb5/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f636c65616e2f7265706f7369746f72792f6261646765732f6770612e737667)](https://codeclimate.com/github/clean/repository)[![Test Coverage](https://camo.githubusercontent.com/332aba72d10a9121d13006b271c24e059ace0bfcc491d20e85c1971c8f6c31e9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f636c65616e2f7265706f7369746f72792f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/clean/repository/coverage)[![Issue Count](https://camo.githubusercontent.com/7ef7db020f24a41e0622462a90ed7c18f9a4447044e077cab15c4b1e203ea9e7/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f636c65616e2f7265706f7369746f72792f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/clean/repository)[![Latest Stable Version](https://camo.githubusercontent.com/a1ee2bfe5506c6abcc6f316a3b8957ebce1c0d38195e041998a4fca586e83830/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e2f7265706f7369746f72792f762f737461626c65)](https://packagist.org/packages/clean/repository)[![Total Downloads](https://camo.githubusercontent.com/75c655329ee392497380e070bf68d67271898cb355f81c23e03464e13cb960a6/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e2f7265706f7369746f72792f646f776e6c6f616473)](https://packagist.org/packages/clean/repository)[![License](https://camo.githubusercontent.com/d58a199a12af29156cdf1ca3ae29cbd06266528b70522821299cebf26329d022/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e2f7265706f7369746f72792f6c6963656e7365)](https://packagist.org/packages/clean/repository)

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

[](#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
------------

[](#installation)

via [Composer](https://packagist.org/packages/clean/repository):

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

Idea and Implementation
-----------------------

[](#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...`, 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:
----------------

[](#working-example)

- [Chinook database repository example](example/chinook)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~94 days

Recently: every ~164 days

Total

9

Last Release

3184d ago

Major Versions

1.1.0 → 2.0.02015-11-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/21d3fe3ceb74869ffa1dd2ca9aac14d6df3e9e4209cfa8ed9c602875d590959b?d=identicon)[romannowicki](/maintainers/romannowicki)

---

Top Contributors

[![krzysztof-magosa](https://avatars.githubusercontent.com/u/6112411?v=4)](https://github.com/krzysztof-magosa "krzysztof-magosa (2 commits)")[![peengle](https://avatars.githubusercontent.com/u/305179?v=4)](https://github.com/peengle "peengle (1 commits)")

---

Tags

repository pattern

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clean-repository/health.svg)

```
[![Health](https://phpackages.com/badges/clean-repository/health.svg)](https://phpackages.com/packages/clean-repository)
```

###  Alternatives

[friendsoftypo3/dashboard

Dashboard for TYPO3

183.9k](/packages/friendsoftypo3-dashboard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
