Skip to content

Commit

Permalink
Update message producer to support PSB v4
Browse files Browse the repository at this point in the history
- Package + classes are renamed to *message producer
- Classes are adjusted to use new prooph/common message handling
- Coveralls added
- Dependencies updated
- php-cs-fixer added
  • Loading branch information
Alexander Miertsch committed Aug 30, 2015
1 parent 05c853e commit 88ae868
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 124 deletions.
4 changes: 4 additions & 0 deletions .coveralls.yml
@@ -0,0 +1,4 @@
# for php-coveralls
service_name: travis-ci
src_dir: src
coverage_clover: build/logs/clover.xml
38 changes: 38 additions & 0 deletions .php_cs
@@ -0,0 +1,38 @@
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->in('src')
->in('tests');
$config = Symfony\CS\Config\Config::create();
$config->level(null);
$config->fixers(
array(
'braces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'function_call_space',
'function_declaration',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'lowercase_keywords',
'parenthesis',
'multiple_use',
'method_argument_space',
'object_operator',
'php_closing_tag',
'remove_lines_between_uses',
'short_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
'unused_use',
'visibility',
'whitespacy_lines',
)
);
$config->finder($finder);
return $config;
14 changes: 12 additions & 2 deletions .travis.yml
Expand Up @@ -3,12 +3,22 @@ language: php
php:
- 5.5
- 5.6
- 7

matrix:
allow_failures:
- php: 7

before_script:
- composer self-update
- composer install --dev --prefer-source
- composer update

script:
- php ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml
- ./vendor/bin/php-cs-fixer fix -v --diff --dry-run

script: phpunit
after_script:
- php vendor/bin/coveralls -v

notifications:
webhooks:
Expand Down
19 changes: 11 additions & 8 deletions README.md
@@ -1,25 +1,28 @@
Bernard message dispatcher for ProophServiceBus
==================================================
Bernard Message Producer for Prooph Service Bus
===============================================

[![Build Status](https://travis-ci.org/prooph/psb-bernard-dispatcher.svg?branch=master)](https://travis-ci.org/prooph/psb-bernard-dispatcher)
[![Build Status](https://travis-ci.org/prooph/psb-bernard-producer.svg)](https://travis-ci.org/prooph/psb-bernard-producer)
[![Coverage Status](https://coveralls.io/repos/prooph/psb-bernard-producer/badge.svg?branch=master&service=github)](https://coveralls.io/github/prooph/psb-bernard-producer?branch=master)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/prooph/improoph)

Use [Bernard](http://bernardphp.com/en/latest/) as message dispatcher for [ProophServiceBus](https://github.com/prooph/service-bus).
Use [Bernard](https://github.com/bernardphp/bernard) as message producer for [Prooph Service Bus](https://github.com/prooph/service-bus).

# Installation

You can install the dispatcher via composer by adding `"prooph/psb-bernard-dispatcher": "~0.1"` as requirement to your composer.json.
You can install the producer via composer by adding `"prooph/psb-bernard-producer": "~0.4"` as requirement to your composer.json.

Usage
-----

Check the [BernardMessageDispatcherTest](tests/BernardMessageDispatcherTest.php). Set up the dispatcher is a straightforward task. Most of
Check the [BernardMessageProducerTest](tests/BernardMessageProducerTest.php). Set up the producer is a straightforward task. Most of
the required components are provided by PSB and Bernard. This package only provides the glue code needed to let both
systems work together.

# Support

- Ask questions on [prooph-users](https://groups.google.com/forum/?hl=de#!forum/prooph) google group.
- File issues at [https://github.com/prooph/psb-bernard-dispatcher/issues](https://github.com/prooph/psb-bernard-dispatcher/issues).
- File issues at [https://github.com/prooph/psb-bernard-producer/issues](https://github.com/prooph/psb-bernard-producer/issues).
- Say hello in the [prooph gitter](https://gitter.im/prooph/improoph) chat.

# Contribute

Expand All @@ -29,4 +32,4 @@ To establish a consistent code quality, please provide unit tests for all your c
License
-------

Released under the [New BSD License](https://github.com/prooph/psb-bernard-dispatcher/blob/master/LICENSE).
Released under the [New BSD License](LICENSE).
18 changes: 10 additions & 8 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "prooph/psb-bernard-dispatcher",
"description": "Bernard message dispatcher for PSB",
"homepage": "https://github.com/prooph/psb-bernard-dispatcher",
"name": "prooph/psb-bernard-producer",
"description": "Bernard Message Producer for Prooph Service Bus",
"homepage": "https://github.com/prooph/psb-bernard-producer",
"license": "BSD-3-Clause",
"authors": [
{
Expand All @@ -16,27 +16,29 @@
],
"keywords": [
"prooph",
"php",
"cqrs",
"CQRS",
"messaging",
"bernard"
],
"require": {
"php": ">=5.5",
"prooph/common": "^3.5",
"bernard/bernard": "~0.12"
},
"require-dev": {
"prooph/service-bus": "dev-master",
"phpunit/phpunit": "3.7.*",
"doctrine/dbal" : "~2.4"
"phpunit/phpunit": "~4.7",
"doctrine/dbal" : "~2.4",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-4": {
"Prooph\\ServiceBus\\Message\\Bernard\\": "src/"
}
},
"autoload-dev": {
"psr-0": {
"psr-4": {
"Prooph\\ServiceBusTest\\": "vendor/prooph/service-bus/tests/"
}
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -10,7 +10,7 @@
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuite name="Prooph ServiceBus Bernard MessageDispatcher Test Suite">
<testsuite name="Prooph ServiceBus Bernard MessageProducer Test Suite">
<directory>./tests/</directory>
</testsuite>

Expand Down
36 changes: 14 additions & 22 deletions src/BernardMessage.php
@@ -1,18 +1,18 @@
<?php
/*
* This file is part of the codeliner/psb-bernard-dispatcher.
* (c) Alexander Miertsch <kontakt@codeliner.ws>
* This file is part of the prooph/psb-bernard-dispatcher.
* (c) 2014 - 2015 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 31.10.14 - 15:16
*
* Date: 10/31/14 - 03:08 PM
*/

namespace Prooph\ServiceBus\Message\Bernard;

use Bernard\Message;
use Prooph\Common\Messaging\RemoteMessage;
use Prooph\Common\Messaging\Message as ProophMessage;

/**
* Class BernardMessage
Expand All @@ -23,37 +23,29 @@
class BernardMessage implements Message
{
/**
* @var RemoteMessage
* @var ProophMessage
*/
private $remoteMessage;
private $proophMessage;

public static function fromRemoteMessage(RemoteMessage $remoteMessage) {
public static function fromProophMessage(ProophMessage $remoteMessage)
{
$instance = new self();
$instance->remoteMessage = $remoteMessage;
$instance->proophMessage = $remoteMessage;
return $instance;
}
/**
* @return string
*/
public function getName()
{
return $this->remoteMessage->name();
}

/**
* @return array
*/
public function toArray()
{
return $this->remoteMessage->toArray();
return $this->proophMessage->messageName();
}

/**
* @return RemoteMessage
* @return ProophMessage
*/
public function getRemoteMessage()
public function getProophMessage()
{
return $this->remoteMessage;
return $this->proophMessage;
}
}

25 changes: 13 additions & 12 deletions src/BernardRouter.php
@@ -1,19 +1,19 @@
<?php
/*
* This file is part of the codeliner/psb-bernard-dispatcher.
* (c) Alexander Miertsch <kontakt@codeliner.ws>
* This file is part of the prooph/psb-bernard-dispatcher.
* (c) 2014 - 2015 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 31.10.14 - 15:34
*
* Date: 10/31/14 - 03:08 PM
*/

namespace Prooph\ServiceBus\Message\Bernard;

use Bernard\Envelope;
use Bernard\Router;
use Prooph\Common\Messaging\MessageHeader;
use Prooph\Common\Messaging\Message;
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\EventBus;

Expand Down Expand Up @@ -54,26 +54,27 @@ public function map(Envelope $envelope)
{
$message = $envelope->getMessage();

if (! $message instanceof BernardMessage) throw new \InvalidArgumentException(sprintf(
if (! $message instanceof BernardMessage) {
throw new \InvalidArgumentException(sprintf(
"Routing the message %s failed due to wrong message type",
$envelope->getName()
));
}

return array($this, "routeMessage");
return [$this, "routeMessage"];
}

/**
* @param BernardMessage $message
*/
public function routeMessage(BernardMessage $message)
{
$remoteMessage = $message->getRemoteMessage();
$proophMessage = $message->getProophMessage();

if ($remoteMessage->header()->type() === MessageHeader::TYPE_COMMAND) {
$this->commandBus->dispatch($remoteMessage);
if ($proophMessage->messageType() === Message::TYPE_COMMAND) {
$this->commandBus->dispatch($proophMessage);
} else {
$this->eventBus->dispatch($remoteMessage);
$this->eventBus->dispatch($proophMessage);
}
}
}

0 comments on commit 88ae868

Please sign in to comment.