PHPackages                             guillermoandrae/php-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. guillermoandrae/php-repository

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

guillermoandrae/php-repository
==============================

A PHP library that implements the Repository pattern.

3.0.2(4y ago)2613[1 PRs](https://github.com/guillermoandrae/php-repository/pulls)1MITPHPPHP ^8.0CI failing

Since Jun 1Pushed 5mo agoCompare

[ Source](https://github.com/guillermoandrae/php-repository)[ Packagist](https://packagist.org/packages/guillermoandrae/php-repository)[ RSS](/packages/guillermoandrae-php-repository/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (16)Used By (1)

PHP Repository Library
======================

[](#php-repository-library)

[![Travis](https://camo.githubusercontent.com/c8b3a65bc994c59392db6e31a6029abb2a570b0d3c4ccc5dbe5fcefa06466fd9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6775696c6c65726d6f616e647261652f7068702d7265706f7369746f72792e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/guillermoandrae/php-repository) [![Scrutinizer](https://camo.githubusercontent.com/d3c41a56f002ceb5ce70976d58cff24bde9e7230a36e65497472255c63351f95/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6775696c6c65726d6f616e647261652f7068702d7265706f7369746f72792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/guillermoandrae/php-repository/) [![Scrutinizer Coverage](https://camo.githubusercontent.com/7adc6be40dcf26ba408ac153b22eb371a2698721b1bd0d63439925cc3938e56d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6775696c6c65726d6f616e647261652f7068702d7265706f7369746f72792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/guillermoandrae/php-repository/) [![Your Mom Approves](https://camo.githubusercontent.com/306615e05fe325896d59074f173a7163b6a8ca06d2011c5f93200b0b941d79d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617070726f76656425323062792d796f75722532306d6f6d2d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://guillermoandraefisher.com)

I use a simple implementation of the Repository pattern. Often. I've been copying and pasting the same code between projects for longer than I care to admit; I came to my senses recently, and that's why this project now exists.

Installation
------------

[](#installation)

Do this, then relax:

```
composer require guillermoandrae/php-repository

```

Usage
-----

[](#usage)

Before you do anything crazy, [read up on the Repository pattern](https://martinfowler.com/eaaCatalog/repository.html). If, after reading that, you decide you still want to move forward: keep reading.

### Naming Classes

[](#naming-classes)

Your classes should be named according to their data type. For example, if you're dealing with widgets, your repository should be named `WidgetsRepository` and your model should be named `WidgetModel`. Note that the data type in the repository name is pluralized and singular in the model name.

### Define the Namespace

[](#define-the-namespace)

By default, the `RepositoryFactory` class will look for repositories in the `App\Repositories` namespace. If you don't plan on using that namespace, you'll need to tell the factory where your repositories live. Use `RepositoryFactory::setNamespace()` to do that, like so:

```
RepositoryFactory::setNamespace('MyStuff\Repositories');
```

### Creating Repositories

[](#creating-repositories)

Leveraging the repository functionality is as easy as writing the following:

```
namespace App\Repositories; // again, use whatever you like

use Guillermoandrae\Repositories\AbstractRepository;

class WidgetsRepository extends AbstractRepository
{
    public function create(array $data): ModelInterface
    {
        // add your object creation code here
    }
}
```

There are a few methods you need to implement in the classes that inherit from the `AbstractRepository` class. Check out the [`RepositoryInterface`](src/Repositories/RepositoryInterface.php) and [`AbstractRepository`](src/Repositories/AbstractRepository.php) classes for the most up-to-date list.

### Creating Models

[](#creating-models)

Creating models is straightforward:

```
namespace App\Repositories;

use Guillermoandrae\Models\AbstractModel;

final class WidgetModel extends AbstractModel // the "final" is optional
{
    // add your constructor and getters
}
```

I generally build immutable models, but how you use them is entirely up to you.

Testing
-------

[](#testing)

Run the following command to make sure you don't ruin the code coverage percentage:

```
composer check-coverage

```

Run the following command to make sure your code is appropriately styled:

```
composer check-style

```

Run the following command to invoke both of the above commands easily:

```
composer test

```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance50

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~100 days

Recently: every ~109 days

Total

14

Last Release

1645d ago

Major Versions

0.2.0 → 1.0.02018-06-04

1.3.2 → 2.0.02020-10-20

2.0.0 → 3.0.02021-12-28

PHP version history (3 changes)0.1.0PHP ^7.1

1.3.0PHP ^7.2

3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2506dcc85d5af658321cdb08df33f0ebb585c04f24bfcca0f8c05dd6f68bc0f?d=identicon)[guillermoandrae](/maintainers/guillermoandrae)

---

Top Contributors

[![guillermoandrae](https://avatars.githubusercontent.com/u/133861?v=4)](https://github.com/guillermoandrae "guillermoandrae (68 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[topshelfcraft/wordsmith

...because you have the best words.

30348.0k7](/packages/topshelfcraft-wordsmith)[lingaro/magento2-codegen

Magento 2 Code Generator

966.5k](/packages/lingaro-magento2-codegen)[rareloop/hatchet

1042.8k](/packages/rareloop-hatchet)

PHPackages © 2026

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