PHPackages                             gpslab/cqrs - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. gpslab/cqrs

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

gpslab/cqrs
===========

Infrastructure for creating CQRS applications

v2.0.0(6y ago)2858563MITPHPPHP &gt;=7.1.0CI failing

Since Jun 23Pushed 6y ago2 watchersCompare

[ Source](https://github.com/gpslab/cqrs)[ Packagist](https://packagist.org/packages/gpslab/cqrs)[ Docs](https://github.com/gpslab/cqrs)[ RSS](/packages/gpslab-cqrs/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (9)Versions (9)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/ee0f003ebd3aabd6330444d7a2b1bde8b3b6573c5c72f667092478d5caa13e95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f637172732e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/cqrs)[![Total Downloads](https://camo.githubusercontent.com/5bae480c319c46d4c4152539eb6f868b2dfa1eb78555ffd2b8dbfbccc57efe47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f637172732e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/cqrs)[![Build Status](https://camo.githubusercontent.com/0df49a83cf531b85f20d90bdcba83f8163070e905cc2414186a66bc5d78e4022/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f637172732e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/cqrs)[![Coverage Status](https://camo.githubusercontent.com/f0705ad766fac63b93656809688ae81dfc039bb34c208dfca1f261c964944790/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f637172732e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/cqrs?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/414e3acc6a69bfdaf2b897412cc4cb06fe0dded73c9adbd901af29da4c619ced/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f637172732e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/cqrs/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/888979bee963732655cb7563ddb24d264e397a63490a5484e9e0072ef782b9ad/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61373838356331332d363835652d343962632d623165372d3633353031303534306632312e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/a7885c13-685e-49bc-b1e7-635010540f21)[![StyleCI](https://camo.githubusercontent.com/ed365a81051027cc26cb4a80e56e4e55709db17327fd280e9b3880225256a3cd/68747470733a2f2f7374796c6563692e696f2f7265706f732f39323331303133352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/92310135)[![License](https://camo.githubusercontent.com/787ed00565aadd2a7edda04d2e81ab29a064683014a5c38e7742fe50cf50f835/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f637172732e7376673f6d61784167653d33363030)](https://github.com/gpslab/cqrs)

CQRS
====

[](#cqrs)

Infrastructure for creating [CQRS](https://martinfowler.com/bliki/CQRS.html) applications.

[![CQRS base scheme](cqrs_schema.png)](cqrs_schema.png)

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

[](#installation)

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

```
composer require gpslab/cqrs
```

Command
-------

[](#command)

- **[Simple usage](docs/command/simple_usage.md)**
- [Bus](docs/command/command_bus.md)
- Handler
    - [Create handler](docs/command/handler.md)
    - Locator and Subscribers
        - [Direct binding locator](docs/command/locator/direct_binding.md)
        - [PSR-11 Container locator](docs/command/locator/psr-11_container.md) *([PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
        - [Symfony container locator](docs/command/locator/symfony_container.md) *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
- [Queue](docs/command/queue/queue.md)
    - [Pull](docs/command/queue/pull/pull.md)
        - [Memory queue](docs/command/queue/pull/memory.md)
        - [Memory unique queue](docs/command/queue/pull/memory_unique.md)
        - [Predis queue](docs/command/queue/pull/predis.md)
        - [Predis unique queue](docs/command/queue/pull/predis_unique.md)
    - [Subscribe](docs/command/queue/subscribe/subscribe.md)
        - [Executing queue](docs/command/queue/subscribe/executing.md)
        - [Predis queue](docs/command/queue/subscribe/predis.md)
    - Serialize command
        - [Optimized serializer](docs/command/queue/serialize/optimized.md)
        - [Payload serializer](docs/command/queue/serialize/payload.md)
- [Middleware](https://github.com/gpslab/middleware)
- [Payload](https://github.com/gpslab/payload)

### Simple usage commands

[](#simple-usage-commands)

Commands, in the [CQRS](https://martinfowler.com/bliki/CQRS.html) approach, are designed to change the data in the application.

For example, consider the procedure for renaming an article.

Create a command to rename:

```
use GpsLab\Component\Command\Command;

class RenameArticleCommand implements Command
{
    public $article_id;

    public $new_name = '';
}
```

> **Note**
>
> To simplify the filling of the command, you can use [payload](https://github.com/gpslab/payload).

You can use any implementations of [callable type](http://php.net/manual/en/language.types.callable.php) as a command handler. We recommend using public methods of classes as handlers. For example we use [Doctrine ORM](https://github.com/doctrine/doctrine2).

```
use GpsLab\Component\Command\Command;
use Doctrine\ORM\EntityManagerInterface;

class RenameArticleHandler
{
    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function handleRenameArticle(RenameArticleCommand $command): void
    {
        // get article by id
        $article = $this->em->getRepository(Article::class)->find($command->article_id);
        $article->rename($command->new_name);
    }
}
```

And now we register handler and handle command.

```
use GpsLab\Component\Command\Bus\HandlerLocatedCommandBus;
use GpsLab\Component\Command\Handler\Locator\DirectBindingCommandHandlerLocator;

// register command handler in handler locator
$handler = new RenameArticleHandler($em);
$locator = new DirectBindingCommandHandlerLocator();
$locator->registerHandler(RenameArticleCommand::class, [$handler, 'handleRenameArticle']);

// create bus with command handler locator
$bus = new HandlerLocatedCommandBus($locator);

// ...

// create rename article command
$command = new RenameArticleCommand();
$command->article_id = $article_id;
$command->new_name = $new_name;

// handle command
$bus->handle($command);
```

For the asynchronous handle a command you can use `CommandQueue`.

> **Note**
>
> To monitor the execution of commands, you can use [middleware](https://github.com/gpslab/middleware).

Query
-----

[](#query)

- **[Simple usage](docs/query/simple_usage.md)**
- [Bus](docs/query/query_bus.md)
- Handler
    - [Create handler](docs/query/handler.md)
    - Locator and Subscribers
        - [Direct binding locator](docs/query/locator/direct_binding.md)
        - [PSR-11 Container locator](docs/query/locator/psr-11_container.md) *([PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
        - [Symfony container locator](docs/query/locator/symfony_container.md) *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
- [Middleware](https://github.com/gpslab/middleware)
- [Payload](https://github.com/gpslab/payload)
- [Doctrine specification query](https://github.com/gpslab/specification-query)

### Simple usage queries

[](#simple-usage-queries)

Query, in the [CQRS](https://martinfowler.com/bliki/CQRS.html) approach, are designed to get the data in the application.

For example, consider the procedure for get an article by identity.

Create a query:

```
use GpsLab\Component\Query\Query;

class ArticleByIdentityQuery implements Query
{
    public $article_id;
}
```

> **Note**
>
> To simplify the filling of the query, you can use [payload](https://github.com/gpslab/payload).

You can use any implementations of [callable type](http://php.net/manual/en/language.types.callable.php) as a query handler. We recommend using public methods of classes as handlers. For example we use [Doctrine ORM](https://github.com/doctrine/doctrine2).

```
use GpsLab\Component\Query\Query;
use Doctrine\ORM\EntityManagerInterface;

class ArticleByIdentityHandler
{
    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function handleArticleByIdentity(ArticleByIdentityQuery $query)
    {
        // get article by id
        return $this->em->getRepository(Article::class)->find($query->article_id);
    }
}
```

And now we register handler and handle query.

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

// register query handler in handler locator
$handler = new ArticleByIdentityHandler($em);
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ArticleByIdentityQuery::class, [$handler, 'handleArticleByIdentity']);

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

// ...

// create find article query
$query = new ArticleByIdentityQuery();
$query->article_id = $article_id;

// handle query
$article = $bus->handle($query);
```

> **Note**
>
> To monitor the execution of commands, you can use [middleware](https://github.com/gpslab/middleware).

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

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

Recently: every ~235 days

Total

8

Last Release

2305d ago

Major Versions

v1.2.1 → v2.0.02020-01-22

PHP version history (2 changes)v1.0.0PHP &gt;=5.5.0

v2.0.0PHP &gt;=7.1.0

### 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 (198 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

commandcqrsinfrastructuremiddlewarephppredispsr-11psr-3queuesymfonypsr-3symfonyPSR-11prediscqrsinfrastructure

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[bugsnag/bugsnag-symfony

Official BugSnag notifier for Symfony applications.

453.0M3](/packages/bugsnag-bugsnag-symfony)[authbucket/oauth2-symfony-bundle

Symfony OAuth2Bundle

839.2k1](/packages/authbucket-oauth2-symfony-bundle)[bref/logger

All you need to log with Bref on AWS Lambda

331.5M8](/packages/bref-logger)[devthis/console-logg

Effortless artisan console output with your usual Laravel logger

1112.7k](/packages/devthis-console-logg)[gpslab/domain-event

Tools to create the domain layer of your DDD application

1929.3k3](/packages/gpslab-domain-event)

PHPackages © 2026

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