Skip to content
This repository has been archived by the owner on May 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #7 from lcobucci/reorganise-package
Browse files Browse the repository at this point in the history
Reorganise package
  • Loading branch information
lcobucci authored Apr 20, 2018
2 parents b4006ec + beb534d commit d9eb21c
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 1,152 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/infection.json.dist export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
5 changes: 5 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ build:
tests:
override:
- php-scrutinizer-run
- phpcs-run

dependencies:
override:
- composer install --no-interaction --prefer-dist

checks:
php: true
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ script:
jobs:
allow_failures:
- php: nightly
- env: STATIC_ANALYSIS=1

include:
- stage: Code Quality
Expand All @@ -43,12 +44,12 @@ jobs:
- stage: Code Quality
env: STATIC_ANALYSIS=1
script:
- ./vendor/bin/phpstan analyse -c phpstan.neon -l max src tests
- ./vendor/bin/phpstan analyse

- stage: Code Quality
env: MUTATION_TESTS=1
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for mutation tests"; exit 1; fi
script:
- ./vendor/bin/infection --threads=4 --min-msi=91 --min-covered-msi=91
- ./vendor/bin/infection --threads=4 --min-msi=100 --min-covered-msi=100
82 changes: 81 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/lcobucci/chimera-bus-tactician/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/lcobucci/chimera-bus-tactician/?branch=master)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/lcobucci/chimera-bus-tactician/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/lcobucci/chimera-bus-tactician/?branch=master)

> The term Chimera (_/kɪˈmɪərə/_ or _/kaɪˈmɪərə/_) has come to describe any
mythical or fictional animal with parts taken from various animals, or to
describe anything composed of very disparate parts, or perceived as wildly
imaginative, implausible, or dazzling.

There are many many amazing libraries in the PHP community and with the creation
and adoption of the PSRs we don't necessarily need to rely on full stack
frameworks to create a complex and well designed software. Choosing which
components to use and plugging them together can sometimes be a little
challenging.

The goal of this set of packages is to make it easier to do that (without
compromising the quality), allowing you to focus on the behaviour of your
software.

This project provides an implementation for `lcobucci/chimera-foundation` that
uses `league/tactician` as service bus.
uses [`league/tactician`](https://tactician.thephpleague.com) as service bus.

## Installation

Expand All @@ -20,3 +35,68 @@ you can install it using [Composer](http://getcomposer.org).
```shell
composer require lcobucci/chimera-bus-tactician
```

## Usage

The only thing you need to do in order to plug tactician into chimera is to
create an instance of the command bus [as you usually do](https://tactician.thephpleague.com)
and pass it to the decorator:

```php
<?php

use League\Tactician\CommandBus;
use Lcobucci\Chimera\ServiceBus\Tactician\ServiceBus;

$middlewareList = []; // list of middleware to be used to process commands
$commandBus = new ServiceBus(new CommandBus($middlewareList));
```

Usually the write and read concerns have different needs, which means that the
list of middleware will definitely vary, so it's highly suggested that you create
two service buses: a query bus and a command bus:

```php
<?php

use League\Tactician\CommandBus;
use Lcobucci\Chimera\ServiceBus\Tactician\ServiceBus;

$writeMiddleware = []; // list of middleware to be used to process commands
$commandBus = new ServiceBus(new CommandBus($writeMiddleware));

$readMiddleware = []; // list of middleware to be used to process queries
$queryBus = new ServiceBus(new CommandBus($readMiddleware));
```

### Domain to read model conversion

It's a good practice to completely isolate your domain model from your read model
(also known as response model). This is important to prevent UI components (e.g.:
request handlers - HTTP controllers - or CLI commands) from manipulating your
aggregate roots and entities.

We provide the `ReadModelConversionMiddleware` to handle such thing, and it should
be added to your query bus (since nothing is really returned from command buses):

```php
<?php

use League\Tactician\CommandBus;
use Lcobucci\Chimera\ServiceBus\ReadModelConverter\Callback;
use Lcobucci\Chimera\ServiceBus\Tactician\ReadModelConversionMiddleware;
use Lcobucci\Chimera\ServiceBus\Tactician\ServiceBus;

// list of middleware to be used to process queries
$readMiddleware = [
// many different middleware according to your needs
new ReadModelConversionMiddleware(new Callback()), // you can use different strategies if needed
// the handler locator middleware provided by tactician
];

$queryBus = new ServiceBus(new CommandBus($readMiddleware));
```

## License

MIT, see [LICENSE file](https://github.com/lcobucci/chimera-bus-tactician/blob/master/LICENSE).
31 changes: 13 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcobucci/chimera-bus-tactician",
"description": "Tactician implementation connecting lcobucci/chimera-foundation and lcobucci/chimera-routing",
"description": "Service bus adapter for league/tactician",
"type": "library",
"license": "MIT",
"authors": [
Expand All @@ -15,32 +15,27 @@
},
"require": {
"php": "^7.2",
"lcobucci/chimera-foundation": "^1.0@alpha",
"lcobucci/chimera-routing": "^1.0@alpha",
"league/tactician": "^1.0"
"lcobucci/chimera-foundation": "^1.0@rc",
"league/tactician": "^1.0",
"league/tactician-container": "^2.0"
},
"require-dev": {
"doctrine/coding-standard": "^3.0",
"infection/infection": "^0.7",
"league/tactician-container": "^2.0",
"phpstan/phpstan": "^0.9",
"phpstan/phpstan-phpunit": "^0.9",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.2",
"symfony/dependency-injection": "^4.0"
},
"suggest": {
"league/tactician-container": "In order to use any PSR-11 compatible library to load handlers",
"symfony/dependency-injection": "In order to use the provided compiler passes"
"doctrine/coding-standard": "^4.0",
"infection/infection": "^0.8",
"phpstan/phpstan": "^0.10@dev",
"phpstan/phpstan-phpunit": "^0.10@dev",
"phpstan/phpstan-strict-rules": "^0.10@dev",
"phpunit/phpunit": "^7.1",
"squizlabs/php_codesniffer": "^3.2"
},
"autoload": {
"psr-4": {
"Lcobucci\\Chimera\\Bus\\Tactician\\": "src"
"Lcobucci\\Chimera\\ServiceBus\\Tactician\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Lcobucci\\Chimera\\Bus\\Tactician\\Tests\\": "tests"
"Lcobucci\\Chimera\\ServiceBus\\Tactician\\Tests\\": "tests"
}
},
"extra": {
Expand Down
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<file>src</file>
<file>tests</file>

<rule ref="Doctrine" />
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
Expand All @@ -25,4 +27,6 @@
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />
</ruleset>
5 changes: 0 additions & 5 deletions phpstan.neon

This file was deleted.

10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
level: 7
paths:
- src
- tests
37 changes: 0 additions & 37 deletions src/CommandBus.php

This file was deleted.

Loading

0 comments on commit d9eb21c

Please sign in to comment.