PHPackages                             claserre9/doctrine-generic-filter - 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. [Database &amp; ORM](/categories/database)
4. /
5. claserre9/doctrine-generic-filter

ActiveLibrary[Database &amp; ORM](/categories/database)

claserre9/doctrine-generic-filter
=================================

Provide a simple mechanism to filter doctrine queries

1.0.0(2y ago)04MITPHPPHP &gt;=8.1

Since Oct 10Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Doctrine Generic Filter
=======================

[](#doctrine-generic-filter)

This package provides a `GenericRepository` class which is a versatile utility class designed to simplify database operations using the Doctrine ORM library. It provides methods for retrieving paginated results, applying filters, and sorting data from your database entities. This README file will guide you through using this class effectively.

Table of contents
-----------------

[](#table-of-contents)

- Installation
- Usage
- Methods
- Examples
- Contributing
- Licence

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

[](#installation)

To use the `GenericRepository` class, you need to have the Doctrine ORM library set up in your PHP project.

```
composer req claserre9/doctrine-generic-filter
```

Usage
-----

[](#usage)

The `GenericRepository` class provides methods for retrieving data from your database entities with various options:

- `getPaginatedResults`: Retrieves paginated results with optional filters and sorting.
- `getResults`: Retrieves results without pagination but with optional filters and sorting.

Create an instance of the GenericRepository class by injecting the EntityManagerInterface:

```
$entityManager = ...; // Instantiate your EntityManager
$repository = new GenericRepository($entityManager);
```

Methods
-------

[](#methods)

### `getPaginatedResults`

[](#getpaginatedresults)

```
public function getPaginatedResults(
    string $entityClass,
    int $page = self::DEFAULT_PAGE,
    int $limit = self::DEFAULT_LIMIT,
    ?array $filters = []
): array
```

- `$entityClass` (string): The name of the entity for which you want to retrieve results.
- `$page` (int): The current page number (default is 1).
- `$limit` (int): The number of results to fetch per page (default is 10).
- `$filters` (array|null): An array of filters to apply to the query.

Returns an array containing the paginated results along with pagination metadata.

### `getResults`

[](#getresults)

```
public function getResults(
    string $entityClass,
    ?array $filters = []
): array
```

`$entityClass` (string): The name of the entity for which you want to retrieve results. `$filters` (array|null): An array of filters to apply to the query.

Returns an array containing the results without pagination.

Examples
--------

[](#examples)

Here are some examples of how to use the `GenericRepository` class:

```
// Create an instance of GenericRepository (assuming $entityManager is already instantiated).
$repository = new GenericRepository($entityManager);

// Example 1: Get paginated results with filters and ordering.
$results = $repository->getPaginatedResults('Your\Entity\Class', 2, 15, ['column' => ['operator' => 'value']]);

// Example 2: Get results without pagination with filters and ordering.
$results = $repository->getResults('Your\Entity\Class', ['column' => ['operator' => 'value']]);
```

This is the list of all operators supported

- `eq` (equal)
- `neq` (not equal)
- `gt` (greater than)
- `lt` (less than)
- `gte` (greater than or equal)
- `lte` (less than or equal)
- `in`
- `notin` (not in)
- `between`
- `sort`

### Some concrete examples

[](#some-concrete-examples)

```
/** Retrieve paginated results for the User entity with a filter
* on the gender field where it should be equal to 'Male'
*/

$filters = ['gender' => ["eq" => 'Male'],];
$results = $genericRepository->getPaginatedResults(User::class, 1, 10, $filters);
```

```
/** Retrieve paginated results for the User entity with a filter
 * on the age field where it should be less than or equal to 20*
 */
$filters = ['age' => ["lte" => 20]];
$results = $genericRepository->getPaginatedResults(User::class, 1, 20, $filters);
```

```
/**
* Retrieve paginated results for the User entity with a filter
 * on the age field where the age should be between 20 and 30
 */
$filters = ['age' => ["between" => ["start" => 20, "end" => 30]]];
$results = $genericRepository->getPaginatedResults(User::class, 1, 10, $filters);
```

We can also apply sort :

```
/**
* Multiple filters and sort
 */

$filters = [
    'country' => ['eq' => 'China'],
    'gender' => ['eq' => 'Male'],
    'age' =>['sort' => 'DESC'],
    'id' => ['sort' => 'DESC'],
];

$results = $genericRepository->getPaginatedResults(User::class, 1, 10, $filters);
```

Contributing
------------

[](#contributing)

Feel free to contribute to this project by opening issues or pull requests on the GitHub repository.

Licence
-------

[](#licence)

This project is licensed under the MIT License.

This README file provides an overview of the `GenericRepository` class, its usage, and how to get started with it in your PHP project. If you have any questions or encounter issues, please refer to the provided examples and documentation in the code or reach out for support.

Happy coding!

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

945d ago

### Community

Maintainers

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

---

Top Contributors

[![claserre9](https://avatars.githubusercontent.com/u/42743420?v=4)](https://github.com/claserre9 "claserre9 (43 commits)")

---

Tags

ormdoctrinefiltergeneric

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/claserre9-doctrine-generic-filter/health.svg)

```
[![Health](https://phpackages.com/badges/claserre9-doctrine-generic-filter/health.svg)](https://phpackages.com/packages/claserre9-doctrine-generic-filter)
```

###  Alternatives

[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[sonata-project/doctrine-orm-admin-bundle

Integrate Doctrine ORM into the SonataAdminBundle

46117.7M155](/packages/sonata-project-doctrine-orm-admin-bundle)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[data-dog/audit-bundle

Audit bundle for symfony2 and doctrine orm, logs any database change

141901.7k1](/packages/data-dog-audit-bundle)[kdyby/doctrine

Doctrine integration into Nette Framework

1091.0M86](/packages/kdyby-doctrine)

PHPackages © 2026

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