PHPackages                             bartoszbartniczak/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bartoszbartniczak/cqrs

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

bartoszbartniczak/cqrs
======================

Command Query Responsibility Segregation pattern applied in PHP.

1.0.0(9y ago)076Apache 2.0PHP

Since Jan 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/BartoszBartniczak/CQRS)[ Packagist](https://packagist.org/packages/bartoszbartniczak/cqrs)[ RSS](/packages/bartoszbartniczak-cqrs/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

BartoszBartniczak / CQRS [![Build Status](https://camo.githubusercontent.com/70ecb201c3b1cf16b6614272c0bc84fd7477c3ea12f4a2690018e167f9e06053/68747470733a2f2f7472617669732d63692e6f72672f426172746f737a426172746e69637a616b2f435152532e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BartoszBartniczak/CQRS)
==========================================================================================================================================================================================================================================================================================================================

[](#bartoszbartniczak--cqrs-)

Command Query Responsibility Segregation in PHP
-----------------------------------------------

[](#command-query-responsibility-segregation-in-php)

### Table of contents

[](#table-of-contents)

- [Preface](#preface)
- [Components](#components)
    - [Command](#command)
    - [Query](#query)
    - [Command Handler](#command-handler)
        - [Example](#example)
    - [CommandBus](#commandbus)
        - [How to register CommandHandler?](#how-to-register-commandhandler)
        - [How command is executed?](#how-command-is-executed)
        - [How query is executed?](#how-query-is-executed)
        - [Example](#example-1)
- [Tests](#tests)
    - [Unit tests](#unit-tests)

### Preface

[](#preface)

If you do not know what Command Query Responsibility Segregation is, you shoud read a very good article written by Martin Fowler. To read the article click [here](http://martinfowler.com/bliki/CQRS.html).

This library is an implementation of this pattern in PHP.

Below are described main components of the library.

### Components

[](#components)

#### Command

[](#command)

Command usualy represents some Domain logic. It can contain data validation, data procesing, etc.. The result of the Command usualy is saved in database. E.g. RegisterUser, SendEmail, etc.. You should treat the Command as a "data holder". In the constructor parameters, you should pass all the data required to handle the Command.

#### Query

[](#query)

Query is a special type of Command. It looks for data in the Repository, and returs it as a result. E.g. FindUser, FindProduct, etc..

#### Command Handler

[](#command-handler)

It handles the Command. In this object you shoud use the parameters passed in the Command constructor. In this object you can validate, change and process the data. CommandHandlers can be registered in CommandBus. See section \[#how-to-register-commandhandler\].

###### Example

[](#example)

```
