PHPackages                             gpslab/specification-query - 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. gpslab/specification-query

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

gpslab/specification-query
==========================

The simple infrastructure component for use a Doctrine specification as query in CQRS architecture

v1.0.0(9y ago)2261MITPHPPHP &gt;=5.5.0CI failing

Since Jun 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gpslab/specification-query)[ Packagist](https://packagist.org/packages/gpslab/specification-query)[ Docs](https://github.com/gpslab/specification-query)[ RSS](/packages/gpslab-specification-query/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/8fb349207b3f8b7215290f9416bce79f20d109081118fe3d1719e829b0b47496/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/specification-query)[![Total Downloads](https://camo.githubusercontent.com/3ce60c86b401a6d06e7ce321cbd14c7c459a016a89fe8121ddb3c0dbaa73f047/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/specification-query)[![Build Status](https://camo.githubusercontent.com/8ff0061840a3408d367cc09d5500dc3c2ecbc9a0d8d6e9c83cefc1a4524b513f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/specification-query)[![Coverage Status](https://camo.githubusercontent.com/3fa6944028ed6747e3f7c4712ec2cf443ec9a6f3a164cbf233c9d1dfb1773a84/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/specification-query?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0e698b47e39d5947dc45e869a34cd0d23ff6151f418f1bc529b6f6fccd5a8e8f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/specification-query/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/94f01a73627840790cef644d21725fa786a890b940e7ea9329d84bf1670a0aea/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61396532636465372d316362662d343562632d623839642d3635633534663337373936372e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/a9e2cde7-1cbf-45bc-b89d-65c54f377967)[![StyleCI](https://camo.githubusercontent.com/ff438f12eaa98d2822ab51d259c7df10db368e647db6c04d022914ec80d8d2e2/68747470733a2f2f7374796c6563692e696f2f7265706f732f39323338313734362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/92381746)[![License](https://camo.githubusercontent.com/927e0f3461a400b81b70ce600fead899fccf40119092abca84a86e79c43fdcc1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f73706563696669636174696f6e2d71756572792e7376673f6d61784167653d33363030)](https://github.com/gpslab/specification-query)

Doctrine Specification as query in CQRS architecture
====================================================

[](#doctrine-specification-as-query-in-cqrs-architecture)

The simple infrastructure component for use a [Doctrine Specification](https://github.com/Happyr/Doctrine-Specification) as query in [CQRS](https://github.com/gpslab/cqrs) architecture.

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

[](#installation)

Pretty simple with [Composer](http://packagist.org), run:

```
composer require gpslab/specification-query
```

Usage
-----

[](#usage)

You can use Specifications as a simple query.

```
use GpsLab\Component\Query\Bus\HandlerLocatedQueryBus;
use GpsLab\Component\Query\Handler\Locator\DirectBindingQueryHandlerLocator;
use GpsLab\Component\Query\Specification\SpecificationQueryHandler;
use GpsLab\Component\Query\Specification\ObviousSpecificationQuery;

// register query handler in handler locator
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ObviousSpecificationQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);

// create bus with query handler locator
$bus = new HandlerLocatedQueryBus($locator);

// specification for get contact with id = 123
$spec = Spec::eq('id', 123);

// cache the result by 1 hour
$modifier = Spec::cache(3600);

// make specification query
$query = new ObviousSpecificationQuery('AcmeDemo:Contact', $spec, $modifier);

// get contact
$contact = $query_bus->handle($query);
```

### Custom query

[](#custom-query)

You can create custom query for this case.

```
class ContactWithIdentityQuery implements SpecificationQuery
{
    /**
     * @var int
     */
    private $id;

    /**
     * @param int $id
     */
    public function __construct($id)
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function entity()
    {
        return 'AcmeDemo:Contact';
    }

    /**
     * @return Specification
     */
    public function spec()
    {
        return Spec::eq('id', $this->id);
    }

    /**
     * @return ResultModifier|null
     */
    public function modifier()
    {
        return Spec::cache(3600);
    }
}
```

And use it

```
use GpsLab\Component\Query\Bus\HandlerLocatedQueryBus;
use GpsLab\Component\Query\Handler\Locator\DirectBindingQueryHandlerLocator;
use GpsLab\Component\Query\Specification\SpecificationQueryHandler;
use GpsLab\Component\Query\Specification\ObviousSpecificationQuery;

// register query handler in handler locator
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ContactWithIdentityQuery::class, [new SpecificationQueryHandler($em), 'handleSpecification']);

// create bus with query handler locator
$bus = new HandlerLocatedQueryBus($locator);

// make specification query
$query = new ContactWithIdentityQuery(123);

// get contact
$contact = $query_bus->handle($query);
```

License
-------

[](#license)

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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

3295d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (24 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

cqrsdoctrinedoctrine-orminfrastructurephpqueryspecificationspecificationdoctrinequerycqrsdoctrine-orminfrastructure

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gpslab-specification-query/health.svg)

```
[![Health](https://phpackages.com/badges/gpslab-specification-query/health.svg)](https://phpackages.com/packages/gpslab-specification-query)
```

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4585.8M4](/packages/martin-georgiev-postgresql-for-doctrine)[kphoen/rulerz

Powerful implementation of the Specification pattern

8771.3M7](/packages/kphoen-rulerz)[happyr/doctrine-specification

Specification Pattern for your Doctrine repositories

450940.2k8](/packages/happyr-doctrine-specification)[ecodev/graphql-doctrine

Declare GraphQL types from Doctrine entities and attributes

101149.4k5](/packages/ecodev-graphql-doctrine)[kphoen/rulerz-bundle

Symfony2 Bundle for RulerZ

37657.9k1](/packages/kphoen-rulerz-bundle)[rikbruil/doctrine-specification

Doctrine Specification pattern for building queries dynamically and with re-usable classes for composition.

50255.2k2](/packages/rikbruil-doctrine-specification)

PHPackages © 2026

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