PHPackages                             tomaszhanc/cqrs-lite-write-model - 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. tomaszhanc/cqrs-lite-write-model

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

tomaszhanc/cqrs-lite-write-model
================================

0.2.1(8y ago)076MITPHPPHP &gt;=7.1CI failing

Since Nov 19Pushed 8y agoCompare

[ Source](https://github.com/tomaszhanc/cqrs-lite-write-model)[ Packagist](https://packagist.org/packages/tomaszhanc/cqrs-lite-write-model)[ RSS](/packages/tomaszhanc-cqrs-lite-write-model/feed)WikiDiscussions master Synced yesterday

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

CQRS Lite - Write Model
=======================

[](#cqrs-lite---write-model)

[![Build Status](https://camo.githubusercontent.com/55fcfcdb5f00c0247893c798e24beac81851a262bc42344fdcf9dd6ac886eb9d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746f6d61737a68616e632f637172732d6c6974652d77726974652d6d6f64656c2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tomaszhanc/cqrs-lite-write-model/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a028191b907bb25031591e968ecd81361af4682876423d56ffc5c5bc54dab1ca/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746f6d61737a68616e632f637172732d6c6974652d77726974652d6d6f64656c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tomaszhanc/cqrs-lite-write-model/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/48b8b5d0d6c40a0f55e67bea0422a27bedd3d1c7c306ffdfe977f66d8f9222df/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746f6d61737a68616e632f637172732d6c6974652d77726974652d6d6f64656c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tomaszhanc/cqrs-lite-write-model/?branch=master)

Sometimes it happens that you have many different commands which should be handled as one command. On the beginning it looks trivial: just create one command and pass it to `CommandBus`, then create another one and another one. But what with validation for a user? We would like to validate all commands before handling the first one. What if we do it via PATCH request: sometimes we will need to handle only one command, sometimes many - it depends on a request.

Handling multiple commands... or just one
-----------------------------------------

[](#handling-multiple-commands-or-just-one)

Let's assume we have an action for PATCH request and we have two commands: `Rename` and `Describe`. Depends on a request we want to create both of them or only one:

```
public function editAction(Request $request, $id)
{
    $renameFactory = new CommandFactory('name');
    $renameFactory->createBy(function (array $data) use ($id) {
        return new Rename($id, $data['name']);
    });

    $describeFactory = new CommandFactory('description');
    $describeFactory->createBy(function (array $data) use ($id) {
        return new Describe($id, $data['description']);
    });

    $builder = new CommandsBuilder();
    $builder->addCommandFactory($renameFactory);
    $builder->addCommandFactory($describeFactory);

    // $request->request->all() returns all data from the request (something like $_POST)
    $commands = $builder->createCommandsFor($request->request->all());

    // here you can validate commands and then handle them via command bus

    foreach ($commands as $command) {
        $this->commandBus->handle($command);
    }
}
```

Method `CommandsBuilder::createCommandsFor()` will create only those commands which should be created regarding if required fields are available (at least one of them) in the passed data (in the example in `$request->request->all()`). Above example can be simplified by using `CommandsBuilderSupport` trait:

```
use CommandsBuilderSupport;

public function editAction(Request $request, $id)
{
    $this->addCommandFor('name')->createBy(
        function (array $data) use ($id) {
            return new Rename($id, $data['name']);
        }
    );

    $this->addCommandFor('description')->createBy(
        function (array $data) use ($id) {
            return new Describe($id, $data['description']);
        }
    );

    $commands = $this->commandsBuilder->createCommandsFor($request->request->all());

    foreach ($commands as $command) {
        $this->commandBus->handle($command);
    }
}
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Every ~20 days

Total

3

Last Release

3106d ago

### Community

Maintainers

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

---

Top Contributors

[![tomaszhanc](https://avatars.githubusercontent.com/u/7013293?v=4)](https://github.com/tomaszhanc "tomaszhanc (5 commits)")

---

Tags

cqrscqrs litewrite model

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tomaszhanc-cqrs-lite-write-model/health.svg)

```
[![Health](https://phpackages.com/badges/tomaszhanc-cqrs-lite-write-model/health.svg)](https://phpackages.com/packages/tomaszhanc-cqrs-lite-write-model)
```

###  Alternatives

[prooph/service-bus

PHP Enterprise Service Bus Implementation supporting CQRS and DDD

4421.4M32](/packages/prooph-service-bus)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[prooph/event-store-bus-bridge

Marry CQRS with Event Sourcing

37523.5k13](/packages/prooph-event-store-bus-bridge)[smoothphp/querybus

A simple bus for queries

1085.1k](/packages/smoothphp-querybus)[pauci/cqrs

CQRS library

1725.2k3](/packages/pauci-cqrs)[honeybee/honeybee

Library for implementing CQRS driven, event-sourced and distributed architectures.

212.1k4](/packages/honeybee-honeybee)

PHPackages © 2026

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