PHPackages                             jurjean/spray-persistence-bundle - 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. jurjean/spray-persistence-bundle

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

jurjean/spray-persistence-bundle
================================

2.1.1(12y ago)227.9k62PHP

Since Sep 9Pushed 11y ago1 watchersCompare

[ Source](https://github.com/JurJean/SprayPersistenceBundle)[ Packagist](https://packagist.org/packages/jurjean/spray-persistence-bundle)[ RSS](/packages/jurjean-spray-persistence-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (9)Used By (2)

Spray\\PersistenceBundle
========================

[](#spraypersistencebundle)

A Symfony2 bundle that enhances Doctrine2 repository functionality.

[![Build Status](https://camo.githubusercontent.com/91156eb1eed87e3d4160e600cd653b917ab32d91965e68b379afaab857fe3375/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f4a75724a65616e2f537072617950657273697374656e636542756e646c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/JurJean/SprayPersistenceBundle)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/6388ec474cfa78a7357774f1a3d4f546e96b22274c65141ac23062c7e6265b4c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a75724a65616e2f537072617950657273697374656e636542756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f733d66333033386439626330616633393137323466346165323766333133326463616536353230333032)](https://scrutinizer-ci.com/g/JurJean/SprayPersistenceBundle/)[![Code Coverage](https://camo.githubusercontent.com/3313b2b05d7abd5e7c42af2a57ed530dfc3f109485f1abd805a8ec244a9cb0eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a75724a65616e2f537072617950657273697374656e636542756e646c652f6261646765732f636f7665726167652e706e673f733d64373466633038633330323039373464616664353730386432356165366238376637333164313362)](https://scrutinizer-ci.com/g/JurJean/SprayPersistenceBundle/)

Introduction
------------

[](#introduction)

This bundle provides a way to query your objects in an abstract manner:

```
    $articles->filter('currentlyPublished');
    $articles->filter('writtenBy', new Author('Buster'));
    $articles->filter('ascending');
```

It has a common API:

```
    $articleCount = count($articles);
    foreach ($articles as $article) {

    }
```

Allows easy pagination:

```
    foreach ($articles->paginate(1) as $article) {

    }
```

And can be used standalone as well! You don't need symfony, you can integrate it in any framework of choice (however Doctrine is a requirement).

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

[](#installation)

Require "jurjean/spray-persistence-bundle" in your composer.json:

```
    {
        "require": {
            "jurjean/spray-persistence-bundle": "2.2.*@dev"
        }
    }
```

Register SprayPersistenceBundle in your AppKernel:

```
    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
            $bundles = array(
                // ...
                new Spray\PersistenceBundle\SprayPersistenceBundle(),
            );
            return $bundles;
        }
    }
```

The problem
-----------

[](#the-problem)

Doctrine2 provides a nice API that lets you query for entities through a repository. However the repository pattern is not very DRY.

If you want to do queries like described above, you could end up with a repository like so:

```
    class ArticleRepository extends Repository
    {
        public function findCurrentlyPublished($order)
        {

        }

        public function findCurrentlyPublishedAndWrittenBy(Author $author, $order)
        {

        }
    }
```

As you can imagine, the only way to add more conditions is by duplication. That's where the RepositoryFilter comes in.

Entity filters
--------------

[](#entity-filters)

Prioritized entity filters
--------------------------

[](#prioritized-entity-filters)

You may want a filter to be prioritized. To do so you must implement the PrioritizedFilterInterface:

```
    use Doctrine\ORM\QueryBuilder;
    use Spray\PersistenceBundle\EntityFilter\EntityFilterInterface;
    use Spray\PersistenceBundle\EntityFilter\PrioritizedFilterInterface;

    class First implements EntityFilterInterface, PrioritizedFilterInterface
    {
        public function filter(QueryBuilder $queryBuilder, $options = array())
        {

        }

        public function getName()
        {
            return 'first';
        }

        public function getPriority()
        {
            return 100;
        }
    }

    class Last implements EntityFilterInterface, PrioritizedFilterInterface
    {
        public function filter(QueryBuilder $queryBuilder, $options = array())
        {

        }

        public function getName()
        {
            return 'last';
        }

        public function getPriority()
        {
            return -100;
        }
    }
```

No matter in which order you add these filters, the order of execution still would be first and then last.

```
    $repository->filter('last'); // Added at priority level -100
    $repository->filter('first'); // Added at priority level 100, before 'last'
```

Conflicting entity filters
--------------------------

[](#conflicting-entity-filters)

If you have filters that may conflict with each other (for instance if they add a where statement on the same column) you can implement the ConflictingFilterInterface:

```
    use Doctrine\ORM\QueryBuilder;
    use Spray\PersistenceBundle\EntityFilter\ConflictingFilterInterface;

    class ArticlesConflictingWith implements ConflictingFilterInterface
    {
        public function filter(QueryBuilder $queryBuilder, $options = array())
        {

        }

        public function getName()
        {
            return 'conflictingWith';
        }

        public function getConflictingFilters()
        {
            return array('another');
        }
    }
```

If 'another' exists in the repository filter scope, it will be removed if ArticlesConflictingWith is added.

```
    $articles->filter('another');
    $articles->filter('conflictingWith'); // This is now the only filter
```

Filter registry
---------------

[](#filter-registry)

The filter registry is used to provide *repository filters* with available *entity filters*. You can either build them up programmatically, or create registry classes yourself. After that you need to inject the registry into the repository filter.

```
    class ArticleFilters extends FilterRegistry
    {
        public function __construct()
        {
            $this->add(new ArticlesPublishedSince());
            $this->add(new ArticlesWrittenBy());
        }
    }

    $articles = new RepositoryFilter($entityManager->getRepository('Article'));
    $articles->setFilterLocator(new ArticleFilters());

    $articles->filter('publishedSince');
    $articles->filter('writtenBy', new Author('Buster'));
```

Symfony integration
-------------------

[](#symfony-integration)

You can configure your repository filters easily by extending the parent di container definition *spray\_persistence.repository\_filter*, and providing it with an Entity name as argument.

```

                Bundle\Entity\Article

```

Filters are added by tagging them with name *spray\_persistence.entity\_filter*. You can either set them up globally (for all repositories) or locally (for one repository). You make them local by adding *repository* as a tag option.

```

                Bundle\Entity\Article

```

Examples
--------

[](#examples)

For more examples please have a look at the [integration tests for this project](test/Spray/PersistenceBundle/Integration).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

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

Total

5

Last Release

4540d ago

Major Versions

1.0.0 → 2.0.02013-10-21

### Community

Maintainers

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

---

Top Contributors

[![JurJean](https://avatars.githubusercontent.com/u/409761?v=4)](https://github.com/JurJean "JurJean (45 commits)")[![thul](https://avatars.githubusercontent.com/u/1921331?v=4)](https://github.com/thul "thul (7 commits)")[![void-sector](https://avatars.githubusercontent.com/u/5223787?v=4)](https://github.com/void-sector "void-sector (5 commits)")[![marcojanssen](https://avatars.githubusercontent.com/u/2293642?v=4)](https://github.com/marcojanssen "marcojanssen (2 commits)")[![Burgov](https://avatars.githubusercontent.com/u/417674?v=4)](https://github.com/Burgov "Burgov (1 commits)")

### Embed Badge

![Health badge](/badges/jurjean-spray-persistence-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/jurjean-spray-persistence-bundle/health.svg)](https://phpackages.com/packages/jurjean-spray-persistence-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[pixelfederation/doctrine-resettable-em-bundle

Symfony bundle for decorating default entity managers using a resettable decorator.

20113.5k](/packages/pixelfederation-doctrine-resettable-em-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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