Skip to content

Commit bb2f3bb

Browse files
committed
Merging Bundle/SymfonyBridge to master
0 parents  commit bb2f3bb

File tree

73 files changed

+3136
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3136
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.travis.yml export-ignore
4+
/phpunit.xml export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/composer.lock export-ignore
7+
/tests export-ignore

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vendor/
2+
phpunit.xml
3+
composer.lock
4+
.couscous/
5+
/build/
6+
/coverage.xml

.travis.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
sudo: false
2+
3+
language: php
4+
5+
matrix:
6+
include:
7+
- php: 5.6
8+
- php: 7.0
9+
- php: 7.1
10+
- php: 7.2
11+
env: SYMFONY_VERSION=2.7.*
12+
- php: 7.2
13+
env: SYMFONY_VERSION=2.8.*
14+
- php: 7.2
15+
env: SYMFONY_VERSION=3.3.*
16+
- php: 7.2
17+
env: SYMFONY_VERSION=3.4.*
18+
- php: 7.2
19+
env: SYMFONY_VERSION=4.0.*
20+
- php: 7.2
21+
env: SYMFONY_VERSION=4.0.* REQUIRE_PROXY_BRIDGE="" EXTRA_PHPUNIT_PARAMS="--group depTest"
22+
23+
env:
24+
global:
25+
- SYMFONY_VERSION=""
26+
- REQUIRE_PROXY_BRIDGE="yes"
27+
- EXTRA_PHPUNIT_PARAMS="--exclude-group depTest"
28+
29+
before_install:
30+
- composer self-update
31+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/http-kernel:$SYMFONY_VERSION symfony/dependency-injection:$SYMFONY_VERSION symfony/yaml:$SYMFONY_VERSION symfony/config:$SYMFONY_VERSION symfony/monolog-bridge:$SYMFONY_VERSION symfony/framework-bundle:$SYMFONY_VERSION; fi
32+
33+
install:
34+
- composer install --prefer-dist
35+
- if [ "$REQUIRE_PROXY_BRIDGE" == "yes" ] && [ "$SYMFONY_VERSION" != "" ]; then composer require symfony/proxy-manager-bridge:$SYMFONY_VERSION; fi
36+
- if [ "$REQUIRE_PROXY_BRIDGE" == "yes" ] && [ "$SYMFONY_VERSION" == "" ]; then composer require symfony/proxy-manager-bridge; fi
37+
38+
script:
39+
- vendor/bin/phpunit $EXTRA_PHPUNIT_PARAMS
40+
41+
after_success:
42+
- bash <(curl -s https://codecov.io/bash)

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014-2015 Matthias Noback
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SimpleBus/SymfonyBridge
2+
3+
[![Build Status](https://travis-ci.org/SimpleBus/SymfonyBridge.svg?branch=master)](https://travis-ci.org/SimpleBus/SymfonyBridge) [![codecov](https://codecov.io/gh/SimpleBus/SymfonyBridge/branch/master/graph/badge.svg)](https://codecov.io/gh/SimpleBus/SymfonyBridge)
4+
5+
By [Matthias Noback](http://php-and-symfony.matthiasnoback.nl/)
6+
7+
This package contains the following bundles which can be used to integrate
8+
[SimpleBus/MessageBus](https://github.com/SimpleBus/MessageBus) with a Symfony application:
9+
10+
- [CommandBusBundle](http://simplebus.github.io/SymfonyBridge/doc/command_bus_bundle.html)
11+
- [EventBusBundle](http://simplebus.github.io/SymfonyBridge/doc/event_bus_bundle.html)
12+
- [DoctrineORMBridgeBundle](http://simplebus.github.io/SymfonyBridge/doc/doctrine_orm_bridge_bundle.html)
13+
14+
Are you upgrading from a previous version? Read the [upgrade
15+
guide](http://simplebus.github.io/SymfonyBridge/doc/upgrade_guide.html).

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment: false

composer.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "simple-bus/symfony-bridge",
3+
"type": "symfony-bundle",
4+
"description": "Bridge for using command buses and event buses in Symfony projects",
5+
"keywords": ["Symfony", "Doctrine", "event bus", "command bus"],
6+
"homepage": "http://github.com/SimpleBus/SymfonyBridge",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Cliff Odijk",
11+
"email": "cliff@jcid.nl"
12+
},
13+
{
14+
"name": "Matthias Noback",
15+
"email": "matthiasnoback@gmail.com",
16+
"homepage": "http://php-and-symfony.matthiasnoback.nl"
17+
}
18+
],
19+
"require": {
20+
"php": "^5.6 || ^7.0",
21+
"simple-bus/message-bus": "~3.0",
22+
"symfony/http-kernel": "~2.3 || ~3.0 || ~4.0",
23+
"symfony/dependency-injection": "~2.3 || ~3.0 || ~4.0",
24+
"symfony/yaml": "~2.3 || ~3.0 || ~4.0",
25+
"symfony/config": "~2.3 || ~3.0 || ~4.0"
26+
},
27+
"suggest": {
28+
"simple-bus/doctrine-orm-bridge": "For integration with Doctrine ORM",
29+
"doctrine/orm": "For integration with Doctrine ORM",
30+
"doctrine/doctrine-bundle": "For integration with Doctrine ORM",
31+
"symfony/monolog-bundle": "For logging messages",
32+
"symfony/proxy-manager-bridge": "For integration with Symfony and Doctrine ORM"
33+
},
34+
"require-dev": {
35+
"doctrine/doctrine-bundle": "~1.0",
36+
"doctrine/orm": "~2.3",
37+
"phpunit/phpunit": "^5.7 || ^6.0",
38+
"simple-bus/doctrine-orm-bridge": "~5.0",
39+
"symfony/framework-bundle": "~2.0 || ~3.0 || ~4.0",
40+
"symfony/monolog-bridge": "~2.3 || ~3.0 || ~4.0",
41+
"symfony/monolog-bundle": "~2.3 || ~3.0"
42+
},
43+
"autoload": {
44+
"psr-4": {
45+
"SimpleBus\\SymfonyBridge\\": "src"
46+
}
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"SimpleBus\\SymfonyBridge\\Tests\\": "tests"
51+
}
52+
}
53+
}

couscous.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
title: SimpleBus/SymfonyBridge
2+
subTitle: Use SimpleBus/MessageBus in a Symfony application
3+
baseUrl: //simplebus.github.io/SymfonyBridge
4+
menu:
5+
items:
6+
home:
7+
itemId: home
8+
text: Home
9+
relativeUrl: ""
10+
getting_started:
11+
itemId: getting_started
12+
text: Getting started
13+
relativeUrl: doc/getting_started.html
14+
command_bus_bundle:
15+
itemId: command_bus_bundle
16+
text: Command bus bundle
17+
relativeUrl: doc/command_bus_bundle.html
18+
event_bus_bundle:
19+
itemId: event_bus_bundle
20+
text: Event bus bundle
21+
relativeUrl: doc/event_bus_bundle.html
22+
doctrine_orm_bridge_bundle:
23+
itemId: doctrine_orm_bridge_bundle
24+
text: Doctrine ORM bridge bundle
25+
relativeUrl: doc/doctrine_orm_bridge_bundle.html
26+
upgrade_guide:
27+
itemId: upgrade_guide
28+
text: Upgrade guide
29+
relativeUrl: doc/upgrade_guide.html

doc/command_bus_bundle.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
currentMenu: command_bus_bundle
3+
---
4+
5+
# Command bus bundle
6+
7+
Using the building blocks supplied by the [SimpleBus/MessageBus library](https://github.com/SimpleBus/MessageBus) you
8+
can create a command bus, which is basically a message bus, with some middlewares and a map of message handlers. This is
9+
described in the [documentation of MessageBus](http://simplebus.github.io/MessageBus/doc/command_bus.html).
10+
11+
If you use Symfony, you don't have to manually configure a command bus in each project. The [SimpleBus/SymfonyBridge
12+
library](https://github.com/SimpleBus/SymfonyBridge) comes with the `SimpleBusCommandBusBundle` which handles it for
13+
you.
14+
15+
First enable the bundle in your application's kernel:
16+
17+
```php
18+
class AppKernel extends Kernel
19+
{
20+
public function registerBundles()
21+
{
22+
$bundles = array(
23+
...
24+
new SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle()
25+
)
26+
...
27+
}
28+
...
29+
}
30+
```
31+
32+
## Using the command bus
33+
34+
This bundle provides the `command_bus` service which is an instance of `SimpleBus\Message\Bus\MessageBus`. Wherever you
35+
like, you can let it handle commands, e.g. inside a container-aware controller:
36+
37+
```php
38+
// $command is an arbitrary object that will be passed to the command handler
39+
$command = ...;
40+
41+
$this->get('command_bus')->handle($command);
42+
```
43+
44+
However, you are encouraged to properly inject the `command_bus` service as a dependency whenever you need it:
45+
46+
```yaml
47+
services:
48+
some_service:
49+
arguments:
50+
- @command_bus
51+
```
52+
53+
## Registering command handlers
54+
55+
As described in the [MessageBus documentation](http://simplebus.github.io/MessageBus/doc/command_bus.html) you can
56+
delegate the handling of particular commands to command handlers. This bundle allows you to register your own
57+
command handlers by adding the `command_handler` tag to the command handler's service definition:
58+
59+
```yaml
60+
services:
61+
register_user_command_handler:
62+
class: Fully\Qualified\Class\Name\Of\RegisterUserCommandHandler
63+
tags:
64+
- { name: command_handler, handles: Fully\Qualified\Class\Name\Of\RegisterUser }
65+
```
66+
67+
### Auto-Register command handlers
68+
69+
You can omit the `handles` tag attribute if your handler meets the following conditions:
70+
71+
1. Uses the "class_based" command name resolving strategy
72+
2. Handles a single command using the `__invoke` method
73+
3. Has a single, non optional class type hinted `__invoke` method parameter
74+
75+
> #### Command handlers are lazy-loaded
76+
>
77+
> Since only one of the command handlers is going to handle any particular command, command handlers are lazy-loaded.
78+
> This means that their services should be defined as public services (i.e. you can't use `public: false` for them).
79+
80+
> #### Command handlers are callables
81+
>
82+
> Any service that is a [PHP callable](http://php.net/manual/en/language.types.callable.php) itself can be used as a
83+
> command handler. If a service itself is not callable, SimpleBus looks for a `handle` method and calls it. If you want
84+
> to use a custom method, just add a `method` attribute to the `command_handler` tag:
85+
>
86+
> ```yaml
87+
> services:
88+
> register_user_command_handler:
89+
> ...
90+
> tags:
91+
> - { name: command_handler, handles: ..., method: registerUser }
92+
```
93+
94+
## Setting the command name resolving strategy
95+
96+
To find the correct command handler for a given command, the name of the command is used. This can be either 1) its
97+
fully-qualified class name (FQCN) or, 2) if the command implements the `SimpleBus\Message\Name\NamedMessage` interface,
98+
the value returned by its static `messageName()` method. By default, the first strategy is used, but you can configure
99+
it in your application configuration:
100+
101+
```yaml
102+
command_bus:
103+
# default value for this key is "class_based"
104+
command_name_resolver_strategy: named_message
105+
```
106+
107+
When you change the strategy, you also have to change the value of the `handles` attribute of your command handler
108+
service definitions:
109+
110+
```yaml
111+
services:
112+
register_user_command_handler:
113+
class: Fully\Qualified\Class\Name\Of\RegisterUserCommandHandler
114+
tags:
115+
- { name: command_handler, handles: register_user }
116+
```
117+
118+
Make sure that the value of `handles` matches the return value of `RegisterUser::messageName()`.
119+
120+
## Adding command bus middleware
121+
122+
As described in the [MessageBus documentation](http://simplebus.github.io/MessageBus/doc/command_bus.html) you can
123+
extend the behavior of the command bus by adding middleware to it. This bundle allows you to register your own
124+
middleware by adding the `command_bus_middleware` tag to the middleware service definition:
125+
126+
```yaml
127+
services:
128+
specialized_command_bus_middleware:
129+
class: YourSpecializedCommandBusMiddleware
130+
public: false
131+
tags:
132+
- { name: command_bus_middleware, priority: 100 }
133+
```
134+
135+
By providing a value for the `priority` tag attribute you can influence the order in which middlewares are added to the
136+
command bus.
137+
138+
> #### Middlewares are not lazy-loaded
139+
>
140+
> Whenever you use the command bus, you also use all of its middlewares, so command bus middlewares are not lazy-loaded.
141+
> This means that their services should be defined as private services (i.e. you should use `public: false`). See also:
142+
> [Marking Services as public /
143+
> private](http://symfony.com/doc/current/components/dependency_injection/advanced.html#marking-services-as-public-private)
144+
145+
## Logging
146+
147+
If you want to log every command that is being handled, enable logging in `config.yml`:
148+
149+
```yaml
150+
command_bus:
151+
logging: ~
152+
```
153+
154+
Messages will be logged to the `command_bus` channel.

doc/doctrine_orm_bridge_bundle.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
currentMenu: doctrine_orm_bridge_bundle
3+
---
4+
5+
# Doctrine ORM and domain events
6+
7+
As described in the documentation of the [SimpleBus/DoctrineORMBridge
8+
package](https://github.com/SimpleBus/DoctrineORMBridge) library it provides:
9+
10+
- A command bus middleware which [wraps the handling of commands inside a database
11+
transaction](http://simplebus.github.io/DoctrineORMBridge/doc/transactions.md)
12+
- A command bus middleware which [collects domain events recorded by entities and lets the event bus handle
13+
them](http://simplebus.github.io/DoctrineORMBridge/doc/domain_events.md)
14+
15+
> Install SimpleBus/DoctrineORMBridge
16+
>
17+
> Before you continue, first install the `simple-bus/doctrine-orm-bridge` package in your project:
18+
>
19+
> composer require simple-bus/doctrine-orm-bridge
20+
21+
When you enable the `DoctrineORMBridgeBundle` in your project, both features will be automatically registered as
22+
command bus middlewares:
23+
24+
```php
25+
class AppKernel extends Kernel
26+
{
27+
public function registerBundles()
28+
{
29+
$bundles = array(
30+
...
31+
new SimpleBus\SymfonyBridge\DoctrineOrmBridgeBundle()
32+
)
33+
...
34+
}
35+
...
36+
}
37+
```
38+
39+
You can optionally configure which entity manager and connection should be used:
40+
41+
```yaml
42+
# in config.yml
43+
44+
doctrine_orm_bridge:
45+
entity_manager: default
46+
connection: default
47+
```

0 commit comments

Comments
 (0)