From 62be6cea92099fea096cbd17c6ed6c05c3bbb7dc Mon Sep 17 00:00:00 2001 From: Alexander Miertsch Date: Fri, 1 May 2015 16:16:10 +0200 Subject: [PATCH] Move messaging base classes to prooph/common --- .coveralls.yml | 4 + .travis.yml | 6 +- README.md | 4 +- composer.json | 8 +- docs/command_bus.md | 6 +- docs/event_bus.md | 6 +- docs/message_dispatcher.md | 34 ++-- docs/plugins.md | 24 +-- docs/service_bus_system.md | 2 +- examples/quick-start.php | 13 +- src/Prooph/ServiceBus/Command.php | 172 ------------------ src/Prooph/ServiceBus/CommandBus.php | 2 +- src/Prooph/ServiceBus/Event.php | 172 ------------------ src/Prooph/ServiceBus/EventBus.php | 2 +- .../Exception/CommandDispatchException.php | 2 +- .../Exception/EventDispatchException.php | 2 +- .../ServiceBus/Exception/RuntimeException.php | 4 +- .../Exception/ServiceBusException.php | 4 +- .../InvokeStrategy/AbstractInvokeStrategy.php | 2 +- .../InvokeStrategy/CallbackStrategy.php | 4 +- ...wardToRemoteMessageDispatcherStrategy.php} | 32 ++-- .../InvokeStrategy/HandleCommandStrategy.php | 7 +- .../InvokeStrategy/OnEventStrategy.php | 13 +- .../Message/FromMessageTranslator.php | 82 --------- .../Message/FromRemoteMessageTranslator.php | 80 ++++++++ .../Message/InMemoryMessageDispatcher.php | 112 ------------ .../InMemoryRemoteMessageDispatcher.php | 69 +++++++ .../ServiceBus/Message/MessageHeader.php | 137 -------------- .../Message/MessageHeaderInterface.php | 55 ------ .../ServiceBus/Message/MessageInterface.php | 48 ----- .../Message/MessageNameProvider.php | 28 --- .../ServiceBus/Message/PayloadInterface.php | 27 --- ...DomainMessageToRemoteMessageTranslator.php | 52 ++++++ ...erface.php => RemoteMessageDispatcher.php} | 14 +- .../ServiceBus/Message/StandardMessage.php | 103 ----------- .../Message/ToMessageTranslator.php | 87 --------- .../Message/ToMessageTranslatorInterface.php | 34 ---- .../Message/ToRemoteMessageTranslator.php | 36 ++++ src/Prooph/ServiceBus/MessageBus.php | 2 +- .../ServiceBus/Process/CommandDispatch.php | 14 +- .../ServiceBus/Process/EventDispatch.php | 14 +- .../ServiceBus/Process/MessageDispatch.php | 2 +- .../ServiceBus/Router/CommandRouter.php | 4 +- src/Prooph/ServiceBus/Router/EventRouter.php | 4 +- src/Prooph/ServiceBus/Router/RegexRouter.php | 6 +- .../ServiceLocator/ServiceLocatorProxy.php | 2 +- src/Prooph/ServiceBus/StaticBusRegistry.php | 2 +- .../Prooph/ServiceBusTest/CommandBusTest.php | 16 +- tests/Prooph/ServiceBusTest/EventBusTest.php | 16 +- .../Message/MessageHeaderTest.php | 84 --------- .../Message/StandardMessageTest.php | 68 ------- .../ToAndFromMessageTranslatorTest.php | 38 ++-- .../ServiceBusTest/Mock/DoSomething.php | 3 +- .../Mock/DoSomethingHandler.php | 2 +- .../Mock/DoSomethingInvokeStrategy.php | 3 +- .../ServiceBusTest/Mock/OnEventHandler.php | 2 - .../ServiceBusTest/Mock/PayloadMockObject.php | 45 ----- .../ServiceBusTest/Mock/SomethingDone.php | 4 +- .../Mock/SomethingDoneInvokeStrategy.php | 5 +- .../Mock/SomethingDoneListener.php | 9 +- .../Router/CommandRouterTest.php | 4 +- .../ServiceBusTest/Router/EventRouterTest.php | 6 +- .../ServiceBusTest/Router/RegexRouterTest.php | 10 +- 63 files changed, 423 insertions(+), 1431 deletions(-) create mode 100644 .coveralls.yml delete mode 100644 src/Prooph/ServiceBus/Command.php delete mode 100644 src/Prooph/ServiceBus/Event.php rename src/Prooph/ServiceBus/InvokeStrategy/{ForwardToMessageDispatcherStrategy.php => ForwardToRemoteMessageDispatcherStrategy.php} (57%) delete mode 100644 src/Prooph/ServiceBus/Message/FromMessageTranslator.php create mode 100644 src/Prooph/ServiceBus/Message/FromRemoteMessageTranslator.php delete mode 100644 src/Prooph/ServiceBus/Message/InMemoryMessageDispatcher.php create mode 100644 src/Prooph/ServiceBus/Message/InMemoryRemoteMessageDispatcher.php delete mode 100644 src/Prooph/ServiceBus/Message/MessageHeader.php delete mode 100644 src/Prooph/ServiceBus/Message/MessageHeaderInterface.php delete mode 100644 src/Prooph/ServiceBus/Message/MessageInterface.php delete mode 100644 src/Prooph/ServiceBus/Message/MessageNameProvider.php delete mode 100644 src/Prooph/ServiceBus/Message/PayloadInterface.php create mode 100644 src/Prooph/ServiceBus/Message/ProophDomainMessageToRemoteMessageTranslator.php rename src/Prooph/ServiceBus/Message/{MessageDispatcherInterface.php => RemoteMessageDispatcher.php} (52%) delete mode 100644 src/Prooph/ServiceBus/Message/StandardMessage.php delete mode 100644 src/Prooph/ServiceBus/Message/ToMessageTranslator.php delete mode 100644 src/Prooph/ServiceBus/Message/ToMessageTranslatorInterface.php create mode 100644 src/Prooph/ServiceBus/Message/ToRemoteMessageTranslator.php delete mode 100644 tests/Prooph/ServiceBusTest/Message/MessageHeaderTest.php delete mode 100644 tests/Prooph/ServiceBusTest/Message/StandardMessageTest.php delete mode 100644 tests/Prooph/ServiceBusTest/Mock/PayloadMockObject.php diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..5049181 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,4 @@ +# for php-coveralls +service_name: travis-ci +src_dir: src +coverage_clover: build/logs/clover.xml diff --git a/.travis.yml b/.travis.yml index b819c8b..8bfe53d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,10 @@ php: - 5.5 - 5.6 -services: - - redis-server - - before_script: - composer self-update - composer --dev install script: - - php ./vendor/bin/phpunit -c ./tests/. + - php ./vendor/bin/phpunit --coverage-text --coverage-clover ./../build/logs/clover.xml -c ./tests/. diff --git a/README.md b/README.md index fedc08f..54e1c84 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ $commandBus->utilize($router); //Expand command bus with the callback invoke strategy $commandBus->utilize(new CallbackStrategy()); -//Create a new Command -$echoText = EchoText::fromPayload('It works'); +//We create a new Command +$echoText = EchoText::fromString('It works'); //... and dispatch it $commandBus->dispatch($echoText); diff --git a/composer.json b/composer.json index f4fbcae..3bac3a8 100644 --- a/composer.json +++ b/composer.json @@ -25,15 +25,11 @@ "require": { "php": ">=5.5", "beberlei/assert": "~2.0", - "prooph/common" : "~1.4", - "rhumsaa/uuid" : "~2.5" + "prooph/common" : "~1.5" }, "require-dev": { "phpunit/phpunit": "3.7.*", - "chrisboulton/php-resque": "~1.2", - "prooph/event-store": "~1.0", - "prooph/event-sourcing": "~1.0", - "zendframework/zend-servicemanager": "~2.3" + "satooshi/php-coveralls": "dev-master" }, "suggest": { "prooph/event-store": "Use ProophEventStore and let the EventBus dispatch persisted DomainEvents", diff --git a/docs/command_bus.md b/docs/command_bus.md index d376934..4cce7c5 100644 --- a/docs/command_bus.md +++ b/docs/command_bus.md @@ -73,7 +73,7 @@ Following action events are triggered in the listed order: - `initialize`: This action event is triggered right after CommandBus::dispatch($command) is invoked. At this time the CommandDispatch only contains the command. - `detect-message-name` (optional): Before a command handler can be located, the CommandBus needs to know how the command is named. Their are two -possibilities to provide the information. The command can implement the [Prooph\ServiceBus\Message\MessageNameProvider](../src/Prooph/ServiceBus/Message/MessageNameProvider.php) interface. +possibilities to provide the information. The command can implement the [Prooph\Common\Messaging\HasMessageName](https://github.com/prooph/common/blob/master/src/Messaging/HasMessageName.php) interface. In this case the CommandBus picks the command name directly from the command and inject it manually in the CommandDispatch. The `detect-message-name` event is not triggered. If the command does not implement the interface the `detect-message-name` event is triggered and a plugin needs to inject the name using `CommandDispatch::setCommandName`. @@ -98,8 +98,8 @@ attach a monitoring plugin. # Commands A command can nearly be everything. PSB tries to get out of your way as much as it can. You are ask to use your own command implementation or you use the -default [Command](../src/Prooph/ServiceBus/Command.php) class provided by PSB. It is a very good base class and PSB ships with translator plugins to translate a Command into a message -that can be send to a remote interface. Check the [Asynchronous Message Dispatcher](message_dispatcher.md) for more details. However, you can provide +default [Command](https://github.com/prooph/common/blob/master/src/Messaging/Command.php) class provided by prooph/common. It is a very good base class and PSB ships with translator plugins to translate a Command into a remote message +that can be send to a remote interface. Check the [Remote Message Dispatcher](message_dispatcher.md) for more details. However, you can provide your own message translator plugin, a plugin that is capable of detecting the name of the command and an invoke strategy that knows how to invoke your command handlers with the command. Mix and match the plugins provided by PSB with your own ones to decouple your implementation from the PSB infrastructure. diff --git a/docs/event_bus.md b/docs/event_bus.md index 2891b6a..7736713 100644 --- a/docs/event_bus.md +++ b/docs/event_bus.md @@ -74,7 +74,7 @@ Following action events are triggered in the listed order: - `initialize`: This action event is triggered right after EventBus::dispatch($event) is invoked. At this time the EventDispatch only contains the event message. - `detect-message-name` (optional): Before an event message listener can be located, the EventBus needs to know how the event message is named. Their are two -possibilities to provide the information. The event message can implement the [Prooph\ServiceBus\Message\MessageNameProvider](../src/Prooph/ServiceBus/Message/MessageNameProvider.php) interface. +possibilities to provide the information. The event message can implement the [Prooph\Common\Messaging\HasMessageName](https://github.com/prooph/common/blob/master/src/Messaging/HasMessageName.php) interface. In this case the EventBus picks the message name directly from the event message and inject it manually in the EventDispatch. The `detect-message-name` action event is not triggered. If the event message does not implement the interface the `detect-message-name` action event is triggered and a plugin needs to inject the name using `EventDispatch::setEventName`. @@ -102,8 +102,8 @@ attach a monitoring plugin. # Event Messages An event message can nearly be everything. PSB tries to get out of your way as much as it can. You are ask to use your own event message implementation or you use the -default [Event](../src/Prooph/ServiceBus/Event.php) class provided by PSB. It is a very good base class and PSB ships with translator plugins to translate an event message into a Prooph\ServiceBus\Message\StandardMessage -that can be send to a remote interface. Check the [Asynchronous Message Dispatcher](message_dispatcher.md) for more details. However, you can provide +default [DomainEvent](https://github.com/prooph/common/blob/master/src/Messaging/DomainEvent.php) class provided by prooph/common. It is a very good base class and PSB ships with translator plugins to translate an event message into a remote message +that can be send to a remote interface. Check the [Remote Message Dispatcher](message_dispatcher.md) for more details. However, you can provide your own message translator plugin, a plugin that is capable of detecting the name of the event message and an invoke strategy that knows how to invoke your event message listeners with the event message. Mix and match the plugins provided by PSB with your own ones to decouple your implementation from the PSB infrastructure. diff --git a/docs/message_dispatcher.md b/docs/message_dispatcher.md index e076d30..f81b26f 100644 --- a/docs/message_dispatcher.md +++ b/docs/message_dispatcher.md @@ -1,4 +1,4 @@ -Asynchronous MessageDispatcher +RemoteMessageDispatcher ============================== [Back to documentation](../README.md#documentation) @@ -9,7 +9,7 @@ Messaging becomes really interesting when you process your messages asynchronous set up a cron job to periodically check the queue for new messages and process them. The bus implementations of PSB can hide such an asynchronous workflow behind a unified interface. You can start with synchronous message dispatching by routing your messages directly to message handlers and if you later want to improve response times you can switch to -async processing on message basis by routing the appropriate messages to a [MessageDispatcher](../src/Prooph/ServiceBus/Message/MessageDispatcherInterface.php). +async processing on message basis by routing the appropriate messages to a [RemoteMessageDispatcher](../src/Prooph/ServiceBus/Message/RemoteMessageDispatcher.php). ## Synchronous Dispatch ```php @@ -43,31 +43,31 @@ $router->route('SomethingDone')->to(new My\Async\MessageDispatcher()); $eventBus->utilize($router); -//The event needs to be translated to a Prooph\ServiceBus\Message\MessageInterface -//The ForwardToMessageDispatcherStrategy checks if the listener of the event -//is an instance of Prooph\ServiceBus\Message\MessageDispatcherInterface -//and translates the event with the help of a Prooph\ServiceBus\Message\ToMessageTranslatorInterface -$eventBus->utilize(new ForwardToMessageDispatcherStrategy(new ToMessageTranslator())); +//The domain event needs to be translated to a Prooph\Common\Messaging\RemoteMessage +//The ForwardToRemoteMessageDispatcherStrategy checks if the listener of the event +//is an instance of Prooph\ServiceBus\Message\RemoteMessageDispatcher +//and translates the event with the help of a Prooph\ServiceBus\Message\ToRemoteMessageTranslator +$eventBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); -//Now the event is dispatched to a MessageDispatcher instead of a listener +//Now the event is dispatched to a RemoteMessageDispatcher instead of a listener $eventBus->dispatch(new SomethingDone()); -//Behind the scenes the message is translated to an array and pushed on a message queue +//Behind the scenes the remote message is translated to an array and pushed on a message queue //There are various messaging tools available. We try to support the most important ones and //continue to add more. Check the list below for available adapters. If your favorite adapter is //not on the list you can easily implement it -//by implementing the Prooph\ServiceBus\Message\MessageDispatcherInterface +//by implementing the Prooph\ServiceBus\Message\RemoteMessageDispatcher interface // //Now imagine that a worker has pulled the message array from the queue and want to process it -//It can simply create a message object from the array ... -$message = \Prooph\ServiceBus\Message\StandardMessage::fromArray($messageArr); +//It can simply create a remote message object from the array ... +$message = \Prooph\Common\Messaging\RemoteMessage::fromArray($messageArr); -//... set up another EventBus with a Prooph\ServiceBus\Message\FromMessageTranslator -//to translate the incoming message back to an event ... +//... set up another EventBus with a Prooph\ServiceBus\Message\FromRemoteMessageTranslator +//to translate the incoming message back to a domain event ... $eventBus = new EventBus(); -$eventBus->utilize(new FromMessageTranslator()); +$eventBus->utilize(new FromRemoteMessageTranslator()); $router = new EventRouter(); @@ -81,9 +81,9 @@ $eventBus->utilize(new OnInvokeStrategy()); $eventBus->dispatch($message); ``` -# Available MessageDispatchers +# Available RemoteMessageDispatchers -- [InMemoryMessageDispatcher](../src/Prooph/ServiceBus/Message/InMemoryMessageDispatcher.php): useful for tests, +- [InMemoryRemoteMessageDispatcher](../src/Prooph/ServiceBus/Message/InMemoryRemoteMessageDispatcher.php): useful for tests, you can replace your async dispatcher with this one - [PhpResqueMessageDispatcher](https://github.com/prooph/psb-php-resque-dispatcher): Perfect choice for async command processing using a ultra fast redis queue diff --git a/docs/plugins.md b/docs/plugins.md index ca80179..4ed2920 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -97,13 +97,13 @@ by extending the [AbstractInvokeStrategy](../src/Prooph/ServiceBus/InvokeStrateg - `HandleCommandStrategy`: Is responsible for invoking a `handle` method of a command handler. Forces the rule that a command handler should only be responsible for handling one specific command. - `OnEventStrategy`: Prefixes the short class name of an event with `on`. A listener should have a public method named this way: OrderCartUpdater::onArticleWasBought. -- `ForwardToMessageDispatcherStrategy`: This is a special invoke strategy that is capable of translating a command or event to -a [StandardMessage](../src/Prooph/ServiceBus/Message/StandardMessage.php) and invoke a [MessageDispatcher](message_dispatcher.md). -Add this strategy to a bus together with a [ToMessageTranslator](../src/Prooph/ServiceBus/Message/ToMessageTranslatorInterface.php) and -route a command or event to a MessageDispatcher to process the message async: +- `ForwardToRemoteMessageDispatcherStrategy`: This is a special invoke strategy that is capable of translating a command or event to +a [RemoteMessage](https://github.com/prooph/common/blob/master/src/Messaging/RemoteMessage.php) and invoke a [RemoteMessageDispatcher](message_dispatcher.md). +Add this strategy to a bus together with a [ToRemoteMessageTranslator](../src/Prooph/ServiceBus/Message/ToRemoteMessageTranslator.php) and +route a command or event to a RemoteMessageDispatcher to process the message async: ```php -$eventBus->utilize(new ForwardToMessageDispatcherStrategy(new ToMessageTranslator())); +$eventBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); $router = new EventRouter(); @@ -114,16 +114,16 @@ $eventBus->utilize($router); $eventBus->dispatch(new SomethingDone()); ``` -# FromMessageTranslator +# FromRemoteMessageTranslator -The [FromMessageTranslator](../src/Prooph/ServiceBus/Message/FromMessageTranslator.php) plugin does the opposite of the `ForwardToMessageDispatcherStrategy`. -It listens on the `initialize` dispatch action event of a CommandBus or EventBus and if it detects an incoming [message](../src/Prooph/ServiceBus/Message/MessageInterface.php) -it translates the message to a [Command](../src/Prooph/ServiceBus/Command.php) or [Event](../src/Prooph/ServiceBus/Event.php) depending on the type -provided in the [MessageHeader](../src/Prooph/ServiceBus/Message/MessageHeaderInterface.php). A receiver of an asynchronous dispatched message, for example a worker of a -message queue, can pull a [message](../src/Prooph/ServiceBus/Message/MessageInterface.php) from the queue and forward it to a appropriate configured CommandBus or EventBus without additional work. +The [FromRemoteMessageTranslator](../src/Prooph/ServiceBus/Message/FromRemoteMessageTranslator.php) plugin does the opposite of the `ForwardToRemoteMessageDispatcherStrategy`. +It listens on the `initialize` dispatch action event of a CommandBus or EventBus and if it detects an incoming [RemoteMessage](https://github.com/prooph/common/blob/master/src/Messaging/RemoteMessage.php) +it translates the message to a [Command](https://github.com/prooph/common/blob/master/src/Messaging/Command.php) or [DomainEvent](https://github.com/prooph/common/blob/master/src/Messaging/DomainEvent.php) depending on the type +provided in the [MessageHeader](https://github.com/prooph/common/blob/master/src/Messaging/MessageHeader.php). A receiver of an asynchronous dispatched message, for example a worker of a +message queue, can pull a [RemoteMessage](https://github.com/prooph/common/blob/master/src/Messaging/RemoteMessage.php) from the queue and forward it to a appropriate configured CommandBus or EventBus without additional work. *Note: If the message name is an existing class it is used instead of the default implementation. - But the constructor of the class should accept the same arguments as the default implementation does, otherwise you need to use your own message translator. + But the custom message class MUST provide a static `fromRemoteMessage` factory method, otherwise the translator will break! # ServiceLocatorProxy diff --git a/docs/service_bus_system.md b/docs/service_bus_system.md index 1ae43b8..4acd2f6 100644 --- a/docs/service_bus_system.md +++ b/docs/service_bus_system.md @@ -23,5 +23,5 @@ PSB provides both possibilities behind a unified interface. Remember the statement "Messaging means fire and forget". The message sender never knows if the message is processed synchronous or asynchronous. It depends on the bus configuration and/or the used plugins. A message can directly be routed to it's handler. In this case we talk about synchronous -message processing. If the receiver of the message is a [Prooph\ServiceBus\Message\MessageDispatcherInterface](message_dispatcher.md) +message processing. If the receiver of the message is a [Prooph\ServiceBus\Message\RemoteMessageDispatcher](message_dispatcher.md) the message is normally processed asynchronously. diff --git a/examples/quick-start.php b/examples/quick-start.php index 8993abb..7506c6b 100644 --- a/examples/quick-start.php +++ b/examples/quick-start.php @@ -14,10 +14,19 @@ namespace Prooph\ServiceBus\Example\Command { - use Prooph\ServiceBus\Command; + use Prooph\Common\Messaging\Command; class EchoText extends Command { + /** + * @param string $text + * @return EchoText + */ + public static function fromString($text) + { + return new self(__CLASS__, $text); + } + protected function convertPayload($textOrPayload) { if (is_string($textOrPayload)) { @@ -57,7 +66,7 @@ public function getText() $commandBus->utilize(new CallbackStrategy()); //We create a new Command - $echoText = EchoText::fromPayload('It works'); + $echoText = EchoText::fromString('It works'); //... and dispatch it $commandBus->dispatch($echoText); diff --git a/src/Prooph/ServiceBus/Command.php b/src/Prooph/ServiceBus/Command.php deleted file mode 100644 index 24155e8..0000000 --- a/src/Prooph/ServiceBus/Command.php +++ /dev/null @@ -1,172 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 21:03 - */ - -namespace Prooph\ServiceBus; - -use Prooph\ServiceBus\Exception\RuntimeException; -use Prooph\ServiceBus\Message\MessageNameProvider; -use Prooph\ServiceBus\Message\PayloadInterface; -use Rhumsaa\Uuid\Uuid; - -/** - * Class Command - * - * The class can be used as base class for commands, but it is no requirement. - * You can dispatch all kinds of messages as long as you register plugins that are able to handle your messages. - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Command - * @author Alexander Miertsch - */ -class Command implements MessageNameProvider -{ - /** - * @var string - */ - protected $name; - - /** - * @var Uuid - */ - protected $uuid; - - /** - * @var int - */ - protected $version; - - /** - * @var \DateTime - */ - protected $createdOn; - - /** - * @var array - */ - protected $payload = array(); - - /** - * @return Command - */ - public static function getNew() - { - return new static(get_called_class()); - } - - /** - * @param mixed $aPayload - * @return Command - */ - public static function fromPayload($aPayload) - { - return new static(get_called_class(), $aPayload); - } - - /** - * @param string $aMessageName - * @param null $aPayload - * @param int $aVersion - * @param Uuid $aUuid - * @param \DateTime $aCreatedOn - * @throws \Prooph\ServiceBus\Exception\RuntimeException - */ - public function __construct($aMessageName, $aPayload = null, $aVersion = 1, Uuid $aUuid = null, \DateTime $aCreatedOn = null) - { - $this->name = $aMessageName; - - if (!is_null($aPayload)) { - - if (! is_array($aPayload)) { - $aPayload = $this->convertPayload($aPayload); - } - - if (is_array($aPayload)) { - $this->payload = $aPayload; - } elseif ($aPayload instanceof PayloadInterface) { - $this->payload = $aPayload->getArrayCopy(); - } else { - throw new RuntimeException( - sprintf( - "Payload must be an array or instance of Prooph\ServiceBus\Message\PayloadInterface, " - . "instance of %s given.", - ((is_object($aPayload)? get_class($aPayload) : gettype($aPayload))) - ) - ); - } - } - - $this->version = $aVersion; - - if (is_null($aUuid)) { - $aUuid = Uuid::uuid4(); - } - - $this->uuid = $aUuid; - - if (is_null($aCreatedOn)) { - $aCreatedOn = new \DateTime(); - } - - $this->createdOn = $aCreatedOn; - } - - /** - * @return array - */ - public function payload() - { - return $this->payload; - } - - /** - * @return Uuid - */ - public function uuid() - { - return $this->uuid; - } - - /** - * @return int - */ - public function version() - { - return $this->version; - } - - /** - * @return \DateTime - */ - public function createdOn() - { - return $this->createdOn; - } - - /** - * Hook point for extending classes, override this method to convert payload to array - * - * @param mixed $aPayload - * @return mixed - */ - protected function convertPayload($aPayload) - { - return $aPayload; - } - - /** - * @return string Name of the message - */ - public function getMessageName() - { - return $this->name; - } -} - \ No newline at end of file diff --git a/src/Prooph/ServiceBus/CommandBus.php b/src/Prooph/ServiceBus/CommandBus.php index 67910cd..53cd24e 100644 --- a/src/Prooph/ServiceBus/CommandBus.php +++ b/src/Prooph/ServiceBus/CommandBus.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Event.php b/src/Prooph/ServiceBus/Event.php deleted file mode 100644 index d271a3c..0000000 --- a/src/Prooph/ServiceBus/Event.php +++ /dev/null @@ -1,172 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 11.03.14 - 21:13 - */ - -namespace Prooph\ServiceBus; - -use Prooph\ServiceBus\Exception\RuntimeException; -use Prooph\ServiceBus\Message\MessageNameProvider; -use Prooph\ServiceBus\Message\PayloadInterface; -use Rhumsaa\Uuid\Uuid; - -/** - * Class Event - * - * The class can be used as base class for events, but it is no requirement. - * You can dispatch all kinds of messages as long as you register plugins that are able to handle your messages. - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Event - * @author Alexander Miertsch - */ -class Event implements MessageNameProvider -{ - /** - * @var string - */ - protected $name; - - /** - * @var Uuid - */ - protected $uuid; - - /** - * @var int - */ - protected $version; - - /** - * @var \DateTime - */ - protected $occurredOn; - - /** - * @var array - */ - protected $payload = array(); - - /** - * @return Event - */ - public static function getNew() - { - return new static(get_called_class()); - } - - /** - * @param mixed $aPayload - * @return Event - */ - public static function fromPayload($aPayload) - { - return new static(get_called_class(), $aPayload); - } - - /** - * @param string $aMessageName - * @param null $aPayload - * @param int $aVersion - * @param Uuid $aUuid - * @param \DateTime $aOccurredOn - * @throws \Prooph\ServiceBus\Exception\RuntimeException - */ - public function __construct($aMessageName, $aPayload = null, $aVersion = 1, Uuid $aUuid = null, \DateTime $aOccurredOn = null) - { - $this->name = $aMessageName; - - if (!is_null($aPayload)) { - - if (! is_array($aPayload)) { - $aPayload = $this->convertPayload($aPayload); - } - - if (is_array($aPayload)) { - $this->payload = $aPayload; - } elseif ($aPayload instanceof PayloadInterface) { - $this->payload = $aPayload->getArrayCopy(); - } else { - throw new RuntimeException( - sprintf( - "Payload must be an array or instance of Prooph\ServiceBus\Message\PayloadInterface, " - . "instance of %s given.", - ((is_object($aPayload)? get_class($aPayload) : gettype($aPayload))) - ) - ); - } - } - - $this->version = $aVersion; - - if (is_null($aUuid)) { - $aUuid = Uuid::uuid4(); - } - - $this->uuid = $aUuid; - - if (is_null($aOccurredOn)) { - $aOccurredOn = new \DateTime(); - } - - $this->occurredOn = $aOccurredOn; - } - - /** - * @return array - */ - public function payload() - { - return $this->payload; - } - - /** - * @return Uuid - */ - public function uuid() - { - return $this->uuid; - } - - /** - * @return int - */ - public function version() - { - return $this->version; - } - - /** - * @return \DateTime - */ - public function occurredOn() - { - return $this->occurredOn; - } - - /** - * Hook point for extending classes, override this method to convert payload to array - * - * @param mixed $aPayload - * @return mixed - */ - protected function convertPayload($aPayload) - { - return $aPayload; - } - - /** - * @return string Name of the message - */ - public function getMessageName() - { - return $this->name; - } -} - \ No newline at end of file diff --git a/src/Prooph/ServiceBus/EventBus.php b/src/Prooph/ServiceBus/EventBus.php index fcb7ce3..070356f 100644 --- a/src/Prooph/ServiceBus/EventBus.php +++ b/src/Prooph/ServiceBus/EventBus.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Exception/CommandDispatchException.php b/src/Prooph/ServiceBus/Exception/CommandDispatchException.php index 1a95366..29d66d4 100644 --- a/src/Prooph/ServiceBus/Exception/CommandDispatchException.php +++ b/src/Prooph/ServiceBus/Exception/CommandDispatchException.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Exception/EventDispatchException.php b/src/Prooph/ServiceBus/Exception/EventDispatchException.php index c1352ad..88dc891 100644 --- a/src/Prooph/ServiceBus/Exception/EventDispatchException.php +++ b/src/Prooph/ServiceBus/Exception/EventDispatchException.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Exception/RuntimeException.php b/src/Prooph/ServiceBus/Exception/RuntimeException.php index e88665f..06ddefe 100644 --- a/src/Prooph/ServiceBus/Exception/RuntimeException.php +++ b/src/Prooph/ServiceBus/Exception/RuntimeException.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Exception/ServiceBusException.php b/src/Prooph/ServiceBus/Exception/ServiceBusException.php index 14acc4f..dd3c3d7 100644 --- a/src/Prooph/ServiceBus/Exception/ServiceBusException.php +++ b/src/Prooph/ServiceBus/Exception/ServiceBusException.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/InvokeStrategy/AbstractInvokeStrategy.php b/src/Prooph/ServiceBus/InvokeStrategy/AbstractInvokeStrategy.php index 21095d4..a761960 100644 --- a/src/Prooph/ServiceBus/InvokeStrategy/AbstractInvokeStrategy.php +++ b/src/Prooph/ServiceBus/InvokeStrategy/AbstractInvokeStrategy.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/InvokeStrategy/CallbackStrategy.php b/src/Prooph/ServiceBus/InvokeStrategy/CallbackStrategy.php index e0f6fbb..2306fce 100644 --- a/src/Prooph/ServiceBus/InvokeStrategy/CallbackStrategy.php +++ b/src/Prooph/ServiceBus/InvokeStrategy/CallbackStrategy.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/InvokeStrategy/ForwardToMessageDispatcherStrategy.php b/src/Prooph/ServiceBus/InvokeStrategy/ForwardToRemoteMessageDispatcherStrategy.php similarity index 57% rename from src/Prooph/ServiceBus/InvokeStrategy/ForwardToMessageDispatcherStrategy.php rename to src/Prooph/ServiceBus/InvokeStrategy/ForwardToRemoteMessageDispatcherStrategy.php index cc17c27..66a42e0 100644 --- a/src/Prooph/ServiceBus/InvokeStrategy/ForwardToMessageDispatcherStrategy.php +++ b/src/Prooph/ServiceBus/InvokeStrategy/ForwardToRemoteMessageDispatcherStrategy.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,29 +11,31 @@ namespace Prooph\ServiceBus\InvokeStrategy; -use Prooph\ServiceBus\Message\MessageDispatcherInterface; -use Prooph\ServiceBus\Message\MessageInterface; -use Prooph\ServiceBus\Message\ToMessageTranslator; -use Prooph\ServiceBus\Message\ToMessageTranslatorInterface; +use Prooph\ServiceBus\Message\RemoteMessageDispatcher; +use Prooph\ServiceBus\Message\ProophDomainMessageToRemoteMessageTranslator; /** - * Class ForwardToMessageDispatcherStrategy + * Class ForwardToRemoteMessageDispatcherStrategy + * + * This invoke strategy comes into play when a domain message should be dispatched to a + * RemoteMessageDispatcher. The strategy translates the domain message to a Prooph\Common\Messaging\RemoteMessage + * with the help of a ToRemoteMessageTranslator and forwards the RemoteMessage to the RemoteMessageDispatcher. * * @package Prooph\ServiceBus\InvokeStrategy * @author Alexander Miertsch */ -class ForwardToMessageDispatcherStrategy extends AbstractInvokeStrategy +class ForwardToRemoteMessageDispatcherStrategy extends AbstractInvokeStrategy { /** - * @var ToMessageTranslatorInterface + * @var ToRemoteMessageTranslator */ protected $messageTranslator; /** - * @param ToMessageTranslatorInterface $messageTranslator + * @param ToRemoteMessageTranslator $messageTranslator */ public function __construct( - ToMessageTranslatorInterface $messageTranslator = null + ProophDomainMessageToRemoteMessageTranslator $messageTranslator = null ) { $this->messageTranslator = $messageTranslator; @@ -46,9 +48,9 @@ public function __construct( */ protected function canInvoke($aHandler, $aCommandOrEvent) { - if ($aHandler instanceof MessageDispatcherInterface) { + if ($aHandler instanceof RemoteMessageDispatcher) { if ($aCommandOrEvent instanceof MessageInterface - || $this->getMessageTranslator()->canTranslateToMessage($aCommandOrEvent)) { + || $this->getMessageTranslator()->canTranslateToRemoteMessage($aCommandOrEvent)) { return true; } } @@ -65,19 +67,19 @@ protected function invoke($aHandler, $aCommandOrEvent) $message = $aCommandOrEvent; if (! $message instanceof MessageInterface) { - $message = $this->getMessageTranslator()->translateToMessage($aCommandOrEvent); + $message = $this->getMessageTranslator()->translateToRemoteMessage($aCommandOrEvent); } $aHandler->dispatch($message); } /** - * @return ToMessageTranslatorInterface + * @return ToRemoteMessageTranslator */ protected function getMessageTranslator() { if (is_null($this->messageTranslator)) { - $this->messageTranslator = new ToMessageTranslator(); + $this->messageTranslator = new ProophDomainMessageToRemoteMessageTranslator(); } return $this->messageTranslator; diff --git a/src/Prooph/ServiceBus/InvokeStrategy/HandleCommandStrategy.php b/src/Prooph/ServiceBus/InvokeStrategy/HandleCommandStrategy.php index e808f99..9eb1e1c 100644 --- a/src/Prooph/ServiceBus/InvokeStrategy/HandleCommandStrategy.php +++ b/src/Prooph/ServiceBus/InvokeStrategy/HandleCommandStrategy.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -10,8 +10,7 @@ */ namespace Prooph\ServiceBus\InvokeStrategy; - -use Prooph\ServiceBus\Command; +use Prooph\Common\Messaging\Command; /** * Class HandleCommandStrategy diff --git a/src/Prooph/ServiceBus/InvokeStrategy/OnEventStrategy.php b/src/Prooph/ServiceBus/InvokeStrategy/OnEventStrategy.php index 2502c2c..6eb4166 100644 --- a/src/Prooph/ServiceBus/InvokeStrategy/OnEventStrategy.php +++ b/src/Prooph/ServiceBus/InvokeStrategy/OnEventStrategy.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -10,9 +10,8 @@ */ namespace Prooph\ServiceBus\InvokeStrategy; - -use Prooph\ServiceBus\Event; -use Prooph\ServiceBus\Message\MessageNameProvider; +use Prooph\Common\Messaging\DomainEvent; +use Prooph\Common\Messaging\HasMessageName; /** * Class OnEventStrategy @@ -29,7 +28,7 @@ class OnEventStrategy extends AbstractInvokeStrategy */ public function canInvoke($aHandler, $aCommandOrEvent) { - if (! $aCommandOrEvent instanceof Event) { + if (! $aCommandOrEvent instanceof DomainEvent) { return false; } @@ -55,7 +54,7 @@ public function invoke($aHandler, $aCommandOrEvent) */ protected function determineEventName($anEvent) { - $eventName = ($anEvent instanceof MessageNameProvider)? $anEvent->getMessageName() : get_class($anEvent); + $eventName = ($anEvent instanceof HasMessageName)? $anEvent->messageName() : get_class($anEvent); return join('', array_slice(explode('\\', $eventName), -1)); } } diff --git a/src/Prooph/ServiceBus/Message/FromMessageTranslator.php b/src/Prooph/ServiceBus/Message/FromMessageTranslator.php deleted file mode 100644 index 8bdbce8..0000000 --- a/src/Prooph/ServiceBus/Message/FromMessageTranslator.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 23.09.14 - 19:23 - */ - -namespace Prooph\ServiceBus\Message; - -use Prooph\Common\Event\ActionEventDispatcher; -use Prooph\Common\Event\ActionEventListenerAggregate; -use Prooph\Common\Event\DetachAggregateHandlers; -use Prooph\ServiceBus\Process\MessageDispatch; - -/** - * Class FromMessageTranslator - * - * If incoming message is of type Prooph\ServiceBus\Message\MessageInterface - * it is translated to Prooph\ServiceBus\Command|mixed or Prooph\ServiceBus\Event|mixed - * depending on the Prooph\ServiceBus\Message\MessageHeader::TYPE_* and if the message name is an existing class - * - * @see FromMessageTranslator::fromMessageToCommand - * @see FromMessageTranslator::fromMessageToEvent - * - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -class FromMessageTranslator implements ActionEventListenerAggregate -{ - use DetachAggregateHandlers; - - /** - * Plugin listens on MessageDispatch::INITIALIZE with priority 100 - * - * @param MessageDispatch $messageDispatch - */ - public function __invoke(MessageDispatch $messageDispatch) - { - $message = $messageDispatch->getMessage(); - - if ($message instanceof MessageInterface) { - $message = $this->translateFromMessage($message); - - $messageDispatch->setMessage($message); - } - } - - /** - * @param ActionEventDispatcher $events - * - * @return void - */ - public function attach(ActionEventDispatcher $events) - { - $this->trackHandler($events->attachListener(MessageDispatch::INITIALIZE, $this, 100)); - } - - /** - * @param MessageInterface $aMessage - * @return mixed - */ - public function translateFromMessage(MessageInterface $aMessage) - { - $defaultCommandOrEventClass = ($aMessage->header()->type() === MessageHeader::TYPE_COMMAND)? - 'Prooph\ServiceBus\Command' : 'Prooph\ServiceBus\Event'; - - $messageClass = (class_exists($aMessage->name()))? $aMessage->name() : $defaultCommandOrEventClass; - - return new $messageClass( - $aMessage->name(), - $aMessage->payload(), - $aMessage->header()->version(), - $aMessage->header()->uuid(), - $aMessage->header()->createdOn() - ); - } -} - \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/FromRemoteMessageTranslator.php b/src/Prooph/ServiceBus/Message/FromRemoteMessageTranslator.php new file mode 100644 index 0000000..c970f0d --- /dev/null +++ b/src/Prooph/ServiceBus/Message/FromRemoteMessageTranslator.php @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 23.09.14 - 19:23 + */ + +namespace Prooph\ServiceBus\Message; + +use Prooph\Common\Event\ActionEventDispatcher; +use Prooph\Common\Event\ActionEventListenerAggregate; +use Prooph\Common\Event\DetachAggregateHandlers; +use Prooph\Common\Messaging\Command; +use Prooph\Common\Messaging\DomainEvent; +use Prooph\Common\Messaging\MessageHeader; +use Prooph\Common\Messaging\RemoteMessage; +use Prooph\ServiceBus\Process\MessageDispatch; + +/** + * Class FromRemoteMessageTranslator + * + * If the incoming message is of type Prooph\Common\Messaging\RemoteMessage + * it is translated to a Prooph\Common\Messaging\DomainMessage respecting the Prooph\Common\Messaging\MessageHeader::TYPE_* + * and if RemoteMessage::name can be resolved to an existing class it is used instead of the base classes. + * + * Note: A custom command or domain event class MUST implement a static fromRemoteMessage factory method otherwise + * the translator will break! + * + * @package Prooph\ServiceBus\Message + * @author Alexander Miertsch + */ +class FromRemoteMessageTranslator implements ActionEventListenerAggregate +{ + use DetachAggregateHandlers; + + /** + * Plugin listens on MessageDispatch::INITIALIZE with priority 100 + * + * @param MessageDispatch $messageDispatch + */ + public function __invoke(MessageDispatch $messageDispatch) + { + $message = $messageDispatch->getMessage(); + + if ($message instanceof RemoteMessage) { + $message = $this->translateFromRemoteMessage($message); + + $messageDispatch->setMessage($message); + } + } + + /** + * @param ActionEventDispatcher $events + * + * @return void + */ + public function attach(ActionEventDispatcher $events) + { + $this->trackHandler($events->attachListener(MessageDispatch::INITIALIZE, $this, 100)); + } + + /** + * @param RemoteMessage $remoteMessage + * @return mixed + */ + public function translateFromRemoteMessage(RemoteMessage $remoteMessage) + { + $defaultCommandOrEventClass = ($remoteMessage->header()->type() === MessageHeader::TYPE_COMMAND)? + Command::class : DomainEvent::class; + + $messageClass = (class_exists($remoteMessage->name()))? $remoteMessage->name() : $defaultCommandOrEventClass; + + return $messageClass::fromRemoteMessage($remoteMessage); + } +} + \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/InMemoryMessageDispatcher.php b/src/Prooph/ServiceBus/Message/InMemoryMessageDispatcher.php deleted file mode 100644 index df43f12..0000000 --- a/src/Prooph/ServiceBus/Message/InMemoryMessageDispatcher.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 10.03.14 - 20:35 - */ - -namespace Prooph\ServiceBus\Message; - -use Prooph\ServiceBus\CommandBus; -use Prooph\ServiceBus\EventBus; -use Zend\EventManager\EventManager; -use Zend\EventManager\EventManagerInterface; - -/** - * Class InMemoryMessageDispatcher - * - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -class InMemoryMessageDispatcher implements MessageDispatcherInterface -{ - /** - * @var EventManagerInterface - */ - protected $events; - - /** - * @var CommandBus - */ - protected $commandBus; - - /** - * @var EventBus - */ - protected $eventBus; - - /** - * @param CommandBus $commandBus - * @param EventBus $eventBus - */ - public function __construct(CommandBus $commandBus, EventBus $eventBus) - { - $this->commandBus = $commandBus; - $this->eventBus = $eventBus; - } - - /** - * @param MessageInterface $message - * @throws \Exception If handling of message fails - * @return void - */ - public function dispatch(MessageInterface $message) - { - $results = $this->events()->trigger( - __FUNCTION__. '.pre', - $this, - array('message' => $message) - ); - - if ($results->stopped()) { - return; - } - - if ($message->header()->type() === MessageHeader::TYPE_COMMAND) { - - $this->commandBus->dispatch($message); - - - $this->events()->trigger( - __FUNCTION__. '.post', - $this, - array('message' => $message) - ); - - return; - } - - if ($message->header()->type() === MessageHeader::TYPE_EVENT) { - - $this->eventBus->dispatch($message); - - - $this->events()->trigger( - __FUNCTION__. '.post', - $this, - array('message' => $message) - ); - - return; - } - } - - /** - * @return EventManagerInterface - */ - public function events() - { - if (is_null($this->events)) { - $this->events = new EventManager(array( - 'message_dispatcher', - __CLASS__ - )); - } - - return $this->events; - } -} diff --git a/src/Prooph/ServiceBus/Message/InMemoryRemoteMessageDispatcher.php b/src/Prooph/ServiceBus/Message/InMemoryRemoteMessageDispatcher.php new file mode 100644 index 0000000..018db2c --- /dev/null +++ b/src/Prooph/ServiceBus/Message/InMemoryRemoteMessageDispatcher.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 10.03.14 - 20:35 + */ + +namespace Prooph\ServiceBus\Message; + +use Prooph\Common\Messaging\MessageHeader; +use Prooph\Common\Messaging\RemoteMessage; +use Prooph\ServiceBus\CommandBus; +use Prooph\ServiceBus\EventBus; + +/** + * Class InMemoryRemoteMessageDispatcher + * + * @package Prooph\ServiceBus\Message + * @author Alexander Miertsch + */ +class InMemoryRemoteMessageDispatcher implements RemoteMessageDispatcher +{ + /** + * @var CommandBus + */ + protected $commandBus; + + /** + * @var EventBus + */ + protected $eventBus; + + /** + * @param CommandBus $commandBus + * @param EventBus $eventBus + */ + public function __construct(CommandBus $commandBus, EventBus $eventBus) + { + $this->commandBus = $commandBus; + $this->eventBus = $eventBus; + } + + /** + * @param RemoteMessage $message + * @throws \Exception If handling of message fails + * @return void + */ + public function dispatch(RemoteMessage $message) + { + + if ($message->header()->type() === MessageHeader::TYPE_COMMAND) { + + $this->commandBus->dispatch($message); + + return; + } + + if ($message->header()->type() === MessageHeader::TYPE_EVENT) { + + $this->eventBus->dispatch($message); + + return; + } + } +} diff --git a/src/Prooph/ServiceBus/Message/MessageHeader.php b/src/Prooph/ServiceBus/Message/MessageHeader.php deleted file mode 100644 index 27a656a..0000000 --- a/src/Prooph/ServiceBus/Message/MessageHeader.php +++ /dev/null @@ -1,137 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 18:22 - */ - -namespace Prooph\ServiceBus\Message; - -use Rhumsaa\Uuid\Uuid; - -/** - * Class MessageHeader - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -class MessageHeader implements MessageHeaderInterface -{ - const TYPE_COMMAND = 'command'; - const TYPE_EVENT = 'event'; - /** - * @var Uuid - */ - protected $uuid; - - /** - * @var \DateTime - */ - protected $createdOn; - - /** - * @var int - */ - protected $version; - - /** - * Type of the Message, can either be command or event - * - * @var string - */ - protected $type; - - /** - * @param array $aMessageHeaderArray - * @return MessageHeaderInterface - */ - public static function fromArray(array $aMessageHeaderArray) - { - \Assert\that($aMessageHeaderArray) - ->keyExists('uuid') - ->keyExists('createdOn') - ->keyExists('version') - ->keyExists('type'); - - $uuid = Uuid::fromString($aMessageHeaderArray['uuid']); - $createdOn = new \DateTime($aMessageHeaderArray['createdOn']); - - return new static( - $uuid, - $createdOn, - $aMessageHeaderArray['version'], - $aMessageHeaderArray['type'] - ); - } - - /** - * @param Uuid $aUuid - * @param \DateTime $aCreatedOn - * @param int $aVersion - * @param string $aType - */ - public function __construct(Uuid $aUuid, \DateTime $aCreatedOn, $aVersion, $aType) - { - \Assert\that($aVersion) - ->notEmpty('MessageHeader.version must not be empty') - ->integer('MessageHeader.version must be an integer'); - - \Assert\that($aType) - ->inArray(array(self::TYPE_COMMAND, self::TYPE_EVENT), 'MessageHeader.type must be command or event'); - - $this->uuid = $aUuid; - $this->createdOn = $aCreatedOn; - $this->version = $aVersion; - $this->type = $aType; - } - - /** - * @return Uuid - */ - public function uuid() - { - return $this->uuid; - } - - /** - * @return \DateTime - */ - public function createdOn() - { - return $this->createdOn; - } - - /** - * @return int - */ - public function version() - { - return $this->version; - } - - /** - * @return string - */ - public function type() - { - return $this->type; - } - - /** - * @return array - */ - public function toArray() - { - return array( - 'uuid' => $this->uuid()->toString(), - 'createdOn' => $this->createdOn()->format(\DateTime::ISO8601), - 'version' => $this->version(), - 'type' => $this->type() - ); - } -} diff --git a/src/Prooph/ServiceBus/Message/MessageHeaderInterface.php b/src/Prooph/ServiceBus/Message/MessageHeaderInterface.php deleted file mode 100644 index 69f5184..0000000 --- a/src/Prooph/ServiceBus/Message/MessageHeaderInterface.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 15:11 - */ - -namespace Prooph\ServiceBus\Message; - -use Rhumsaa\Uuid\Uuid; - -/** - * Interface MessageHeaderInterface - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Command - * @author Alexander Miertsch - */ -interface MessageHeaderInterface -{ - /** - * @param array $aMessageHeaderArray - * @return MessageHeaderInterface - */ - public static function fromArray(array $aMessageHeaderArray); - - /** - * @return Uuid - */ - public function uuid(); - - /** - * @return \DateTime - */ - public function createdOn(); - - /** - * @return int - */ - public function version(); - - /** - * @return string - */ - public function type(); - - /** - * @return array - */ - public function toArray(); -} \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/MessageInterface.php b/src/Prooph/ServiceBus/Message/MessageInterface.php deleted file mode 100644 index 7dfaf64..0000000 --- a/src/Prooph/ServiceBus/Message/MessageInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 15:36 - */ - -namespace Prooph\ServiceBus\Message; - -/** - * Interface MessageInterface - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -interface MessageInterface -{ - /** - * @param array $aMessageArray - * @return MessageInterface - */ - public static function fromArray(array $aMessageArray); - - /** - * @return string - */ - public function name(); - - /** - * @return MessageHeaderInterface - */ - public function header(); - - /** - * @return array - */ - public function payload(); - - /** - * @return array - */ - public function toArray(); -} \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/MessageNameProvider.php b/src/Prooph/ServiceBus/Message/MessageNameProvider.php deleted file mode 100644 index d0bbe2f..0000000 --- a/src/Prooph/ServiceBus/Message/MessageNameProvider.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 06.07.14 - 18:34 - */ - -namespace Prooph\ServiceBus\Message; - -/** - * Interface MessageNameProvider - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -interface MessageNameProvider -{ - /** - * @return string Name of the message - */ - public function getMessageName(); -} - \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/PayloadInterface.php b/src/Prooph/ServiceBus/Message/PayloadInterface.php deleted file mode 100644 index dc58a69..0000000 --- a/src/Prooph/ServiceBus/Message/PayloadInterface.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 15:08 - */ - -namespace Prooph\ServiceBus\Message; - -/** - * Interface PayloadInterface - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Payload - * @author Alexander Miertsch - */ -interface PayloadInterface -{ - /** - * @return array - */ - public function getArrayCopy(); -} \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/ProophDomainMessageToRemoteMessageTranslator.php b/src/Prooph/ServiceBus/Message/ProophDomainMessageToRemoteMessageTranslator.php new file mode 100644 index 0000000..06a7121 --- /dev/null +++ b/src/Prooph/ServiceBus/Message/ProophDomainMessageToRemoteMessageTranslator.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 11.03.14 - 22:43 + */ + +namespace Prooph\ServiceBus\Message; + +use Prooph\Common\Messaging\DomainMessage; +use Prooph\Common\Messaging\RemoteMessage; +use Prooph\ServiceBus\Exception\RuntimeException; + +/** + * Class ProophDomainMessageToRemoteMessageTranslator + * + * @package Prooph\ServiceBus\Message + * @author Alexander Miertsch + */ +class ProophDomainMessageToRemoteMessageTranslator implements ToRemoteMessageTranslator +{ + /** + * @param $domainMessage + * @return bool + */ + public function canTranslateToRemoteMessage($domainMessage) + { + if ($domainMessage instanceof DomainMessage) return true; + return false; + } + + /** + * @param mixed $domainMessage + * @throws \Prooph\ServiceBus\Exception\RuntimeException + * @return RemoteMessage + */ + public function translateToRemoteMessage($domainMessage) + { + if ($domainMessage instanceof DomainMessage) return $domainMessage->toRemoteMessage(); + + throw new RuntimeException( + sprintf( + "Can not build remote message. Invalid domain message type %s given", + is_object($domainMessage)? get_class($domainMessage) : gettype($domainMessage) + ) + ); + } +} diff --git a/src/Prooph/ServiceBus/Message/MessageDispatcherInterface.php b/src/Prooph/ServiceBus/Message/RemoteMessageDispatcher.php similarity index 52% rename from src/Prooph/ServiceBus/Message/MessageDispatcherInterface.php rename to src/Prooph/ServiceBus/Message/RemoteMessageDispatcher.php index f2551e7..90f3dba 100644 --- a/src/Prooph/ServiceBus/Message/MessageDispatcherInterface.php +++ b/src/Prooph/ServiceBus/Message/RemoteMessageDispatcher.php @@ -1,7 +1,7 @@ + * This file is part of the prooph/service-bus. + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,17 +11,19 @@ namespace Prooph\ServiceBus\Message; +use Prooph\Common\Messaging\RemoteMessage; + /** - * Interface MessageDispatcherInterface + * Interface RemoteMessageDispatcher * * @package Prooph\ServiceBus\Message * @author Alexander Miertsch */ -interface MessageDispatcherInterface +interface RemoteMessageDispatcher { /** - * @param MessageInterface $message + * @param RemoteMessage $message * @return void */ - public function dispatch(MessageInterface $message); + public function dispatch(RemoteMessage $message); } \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/StandardMessage.php b/src/Prooph/ServiceBus/Message/StandardMessage.php deleted file mode 100644 index 330e1d0..0000000 --- a/src/Prooph/ServiceBus/Message/StandardMessage.php +++ /dev/null @@ -1,103 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 18:12 - */ - -namespace Prooph\ServiceBus\Message; - -/** - * Class StandardMessage - * - * @deprecated This class will be removed in v4.0, use the one provided by prooph/common instead - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -class StandardMessage implements MessageInterface -{ - /** - * @var string - */ - protected $name; - - /** - * @var MessageHeaderInterface - */ - protected $header; - - /** - * @var array - */ - protected $payload; - - /** - * @param array $aMessageArray - * @return MessageInterface - */ - public static function fromArray(array $aMessageArray) - { - \Assert\that($aMessageArray)->keyExists('name')->keyExists('header')->keyExists('payload'); - \Assert\that($aMessageArray['name'])->notEmpty()->string(); - \Assert\that($aMessageArray['header'])->isArray(); - \Assert\that($aMessageArray['payload'])->isArray(); - - $header = MessageHeader::fromArray($aMessageArray['header']); - - return new static($aMessageArray['name'], $header, $aMessageArray['payload']); - } - - /** - * @param string $aName - * @param MessageHeaderInterface $aMessageHeader - * @param array $aPayload - */ - public function __construct($aName, MessageHeaderInterface $aMessageHeader, array $aPayload) - { - \Assert\that($aName)->notEmpty('Message.name must not be empty')->string('Message.name must be string'); - - $this->name = $aName; - $this->header = $aMessageHeader; - $this->payload = $aPayload; - } - - /** - * @return string - */ - public function name() - { - return $this->name; - } - - /** - * @return MessageHeaderInterface - */ - public function header() - { - return $this->header; - } - - /** - * @return array - */ - public function payload() - { - return $this->payload; - } - - /** - * @return array - */ - public function toArray() - { - return array( - 'name' => $this->name(), - 'header' => $this->header()->toArray(), - 'payload' => $this->payload() - ); - } -} diff --git a/src/Prooph/ServiceBus/Message/ToMessageTranslator.php b/src/Prooph/ServiceBus/Message/ToMessageTranslator.php deleted file mode 100644 index 56bfb33..0000000 --- a/src/Prooph/ServiceBus/Message/ToMessageTranslator.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 11.03.14 - 22:43 - */ - -namespace Prooph\ServiceBus\Message; - -use Prooph\ServiceBus\Command; -use Prooph\ServiceBus\Event; -use Prooph\ServiceBus\Exception\RuntimeException; - -/** - * Class ToMessageTranslator - * - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -class ToMessageTranslator implements ToMessageTranslatorInterface -{ - /** - * @param $aCommandOrEvent - * @return bool - */ - public function canTranslateToMessage($aCommandOrEvent) - { - if ($aCommandOrEvent instanceof Command) return true; - if ($aCommandOrEvent instanceof Event) return true; - return false; - } - - /** - * @param mixed $aCommandOrEvent - * @throws \Prooph\ServiceBus\Exception\RuntimeException - * @return MessageInterface - */ - public function translateToMessage($aCommandOrEvent) - { - if ($aCommandOrEvent instanceof Command) return $this->fromCommandToMessage($aCommandOrEvent); - if ($aCommandOrEvent instanceof Event) return $this->fromEventToMessage($aCommandOrEvent); - - throw new RuntimeException( - sprintf( - "Can not build message. Invalid command or event type %s given", - is_object($aCommandOrEvent)? get_class($aCommandOrEvent) : gettype($aCommandOrEvent) - ) - ); - } - - /** - * @param mixed $aCommand - * @return MessageInterface - */ - protected function fromCommandToMessage($aCommand) - { - $messageHeader = new MessageHeader( - $aCommand->uuid(), - $aCommand->createdOn(), - $aCommand->version(), - MessageHeader::TYPE_COMMAND - ); - - return new StandardMessage($aCommand->getMessageName(), $messageHeader, $aCommand->payload()); - - } - - /** - * @param mixed $anEvent - * @return MessageInterface - */ - protected function fromEventToMessage($anEvent) - { - $messageHeader = new MessageHeader( - $anEvent->uuid(), - $anEvent->occurredOn(), - $anEvent->version(), - MessageHeader::TYPE_EVENT - ); - - return new StandardMessage($anEvent->getMessageName(), $messageHeader, $anEvent->payload()); - } -} diff --git a/src/Prooph/ServiceBus/Message/ToMessageTranslatorInterface.php b/src/Prooph/ServiceBus/Message/ToMessageTranslatorInterface.php deleted file mode 100644 index a9ab2e9..0000000 --- a/src/Prooph/ServiceBus/Message/ToMessageTranslatorInterface.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 11.03.14 - 21:07 - */ - -namespace Prooph\ServiceBus\Message; - -/** - * Interface ToMessageTranslatorInterface - * - * @package Prooph\ServiceBus\Message - * @author Alexander Miertsch - */ -interface ToMessageTranslatorInterface -{ - /** - * @param $aCommandOrEvent - * @return bool - */ - public function canTranslateToMessage($aCommandOrEvent); - - /** - * @param mixed $aCommandOrEvent - * @return MessageInterface - */ - public function translateToMessage($aCommandOrEvent); -} - \ No newline at end of file diff --git a/src/Prooph/ServiceBus/Message/ToRemoteMessageTranslator.php b/src/Prooph/ServiceBus/Message/ToRemoteMessageTranslator.php new file mode 100644 index 0000000..a582e0a --- /dev/null +++ b/src/Prooph/ServiceBus/Message/ToRemoteMessageTranslator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 11.03.14 - 21:07 + */ + +namespace Prooph\ServiceBus\Message; + +use Prooph\Common\Messaging\RemoteMessage; + +/** + * Interface ToRemoteMessageTranslator + * + * @package Prooph\ServiceBus\Message + * @author Alexander Miertsch + */ +interface ToRemoteMessageTranslator +{ + /** + * @param $domainMessage + * @return bool + */ + public function canTranslateToRemoteMessage($domainMessage); + + /** + * @param mixed $domainMessage + * @return RemoteMessage + */ + public function translateToRemoteMessage($domainMessage); +} + \ No newline at end of file diff --git a/src/Prooph/ServiceBus/MessageBus.php b/src/Prooph/ServiceBus/MessageBus.php index d2c6df0..d49f627 100644 --- a/src/Prooph/ServiceBus/MessageBus.php +++ b/src/Prooph/ServiceBus/MessageBus.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Process/CommandDispatch.php b/src/Prooph/ServiceBus/Process/CommandDispatch.php index 191b5d4..03bccef 100644 --- a/src/Prooph/ServiceBus/Process/CommandDispatch.php +++ b/src/Prooph/ServiceBus/Process/CommandDispatch.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,10 +11,10 @@ namespace Prooph\ServiceBus\Process; +use Prooph\Common\Messaging\HasMessageName; +use Prooph\Common\Messaging\MessageHeader; +use Prooph\Common\Messaging\RemoteMessage; use Prooph\ServiceBus\CommandBus; -use Prooph\ServiceBus\Message\MessageHeader; -use Prooph\ServiceBus\Message\MessageInterface; -use Prooph\ServiceBus\Message\MessageNameProvider; /** * Class CommandDispatch @@ -37,11 +37,11 @@ public static function initializeWith($command, CommandBus $commandBus) { $instance = new self(self::INITIALIZE, $commandBus, array('message' => $command)); - if ($command instanceof MessageNameProvider) { - $instance->setMessageName($command->getMessageName()); + if ($command instanceof HasMessageName) { + $instance->setMessageName($command->messageName()); } - if ($command instanceof MessageInterface) { + if ($command instanceof RemoteMessage) { if ($command->header()->type() !== MessageHeader::TYPE_COMMAND) { throw new \InvalidArgumentException( sprintf("Message %s cannot be handled. Message is not of type command.", $command->name()) diff --git a/src/Prooph/ServiceBus/Process/EventDispatch.php b/src/Prooph/ServiceBus/Process/EventDispatch.php index 59023f5..7f1adbb 100644 --- a/src/Prooph/ServiceBus/Process/EventDispatch.php +++ b/src/Prooph/ServiceBus/Process/EventDispatch.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,11 +11,11 @@ namespace Prooph\ServiceBus\Process; +use Prooph\Common\Messaging\HasMessageName; +use Prooph\Common\Messaging\MessageHeader; +use Prooph\Common\Messaging\RemoteMessage; use Prooph\ServiceBus\EventBus; use Prooph\ServiceBus\Exception\RuntimeException; -use Prooph\ServiceBus\Message\MessageHeader; -use Prooph\ServiceBus\Message\MessageInterface; -use Prooph\ServiceBus\Message\MessageNameProvider; /** * Class EventDispatch @@ -38,11 +38,11 @@ public static function initializeWith($event, EventBus $eventBus) { $instance = new self(self::INITIALIZE, $eventBus, array('message' => $event)); - if ($event instanceof MessageNameProvider) { - $instance->setMessageName($event->getMessageName()); + if ($event instanceof HasMessageName) { + $instance->setMessageName($event->messageName()); } - if ($event instanceof MessageInterface) { + if ($event instanceof RemoteMessage) { if ($event->header()->type() !== MessageHeader::TYPE_EVENT) { throw new \InvalidArgumentException( sprintf("Message %s cannot be handled. Message is not of type event.", $event->name()) diff --git a/src/Prooph/ServiceBus/Process/MessageDispatch.php b/src/Prooph/ServiceBus/Process/MessageDispatch.php index e473c3d..f03ef4a 100644 --- a/src/Prooph/ServiceBus/Process/MessageDispatch.php +++ b/src/Prooph/ServiceBus/Process/MessageDispatch.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/Router/CommandRouter.php b/src/Prooph/ServiceBus/Router/CommandRouter.php index 03b8740..c10afe3 100644 --- a/src/Prooph/ServiceBus/Router/CommandRouter.php +++ b/src/Prooph/ServiceBus/Router/CommandRouter.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -111,7 +111,7 @@ public function to($commandHandler) */ public function onRouteCommand(CommandDispatch $commandDispatch) { - if (is_null($commandDispatch->getCommandName())) { + if (is_null($commandDispatch->getCommandName()) && $commandDispatch->isLoggingEnabled()) { $commandDispatch->getLogger()->notice( sprintf("%s: CommandDispatch contains no command name", get_called_class()) ); diff --git a/src/Prooph/ServiceBus/Router/EventRouter.php b/src/Prooph/ServiceBus/Router/EventRouter.php index 0db7669..0944e4d 100644 --- a/src/Prooph/ServiceBus/Router/EventRouter.php +++ b/src/Prooph/ServiceBus/Router/EventRouter.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -132,7 +132,7 @@ public function andTo($eventListener) */ public function onRouteEvent(EventDispatch $eventDispatch) { - if (is_null($eventDispatch->getEventName())) { + if (is_null($eventDispatch->getEventName()) && $eventDispatch->isLoggingEnabled()) { $eventDispatch->getLogger()->notice( sprintf("%s: EventDispatch contains no event name", get_called_class()) ); diff --git a/src/Prooph/ServiceBus/Router/RegexRouter.php b/src/Prooph/ServiceBus/Router/RegexRouter.php index babc861..ce17058 100644 --- a/src/Prooph/ServiceBus/Router/RegexRouter.php +++ b/src/Prooph/ServiceBus/Router/RegexRouter.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -132,7 +132,7 @@ public function onRoute(MessageDispatch $messageDispatch) */ private function onRouteCommand(CommandDispatch $commandDispatch) { - if (is_null($commandDispatch->getCommandName())) { + if (is_null($commandDispatch->getCommandName()) && $commandDispatch->isLoggingEnabled()) { $commandDispatch->getLogger()->notice( sprintf("%s: CommandDispatch contains no command name", get_called_class()) ); @@ -165,7 +165,7 @@ private function onRouteCommand(CommandDispatch $commandDispatch) */ private function onRouteEvent(EventDispatch $eventDispatch) { - if (is_null($eventDispatch->getEventName())) { + if (is_null($eventDispatch->getEventName()) && $eventDispatch->isLoggingEnabled()) { $eventDispatch->getLogger()->notice( sprintf("%s: EventDispatch contains no event name", get_called_class()) ); diff --git a/src/Prooph/ServiceBus/ServiceLocator/ServiceLocatorProxy.php b/src/Prooph/ServiceBus/ServiceLocator/ServiceLocatorProxy.php index f1fa783..453bc75 100644 --- a/src/Prooph/ServiceBus/ServiceLocator/ServiceLocatorProxy.php +++ b/src/Prooph/ServiceBus/ServiceLocator/ServiceLocatorProxy.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Prooph/ServiceBus/StaticBusRegistry.php b/src/Prooph/ServiceBus/StaticBusRegistry.php index 9335dea..04a0273 100644 --- a/src/Prooph/ServiceBus/StaticBusRegistry.php +++ b/src/Prooph/ServiceBus/StaticBusRegistry.php @@ -1,7 +1,7 @@ + * (c) 2014 - 2015 prooph software GmbH * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Prooph/ServiceBusTest/CommandBusTest.php b/tests/Prooph/ServiceBusTest/CommandBusTest.php index f1d71b0..e68f0e5 100644 --- a/tests/Prooph/ServiceBusTest/CommandBusTest.php +++ b/tests/Prooph/ServiceBusTest/CommandBusTest.php @@ -14,10 +14,10 @@ use Prooph\Common\ServiceLocator\ZF2\Zf2ServiceManagerProxy; use Prooph\ServiceBus\CommandBus; use Prooph\ServiceBus\EventBus; -use Prooph\ServiceBus\InvokeStrategy\ForwardToMessageDispatcherStrategy; -use Prooph\ServiceBus\Message\FromMessageTranslator; -use Prooph\ServiceBus\Message\InMemoryMessageDispatcher; -use Prooph\ServiceBus\Message\ToMessageTranslator; +use Prooph\ServiceBus\InvokeStrategy\ForwardToRemoteMessageDispatcherStrategy; +use Prooph\ServiceBus\Message\FromRemoteMessageTranslator; +use Prooph\ServiceBus\Message\InMemoryRemoteMessageDispatcher; +use Prooph\ServiceBus\Message\ProophDomainMessageToRemoteMessageTranslator; use Prooph\ServiceBus\Router\CommandRouter; use Prooph\ServiceBus\ServiceLocator\ServiceLocatorProxy; use Prooph\ServiceBusTest\Mock\DoSomething; @@ -57,18 +57,18 @@ protected function setUp() $this->commandBus->utilize($router); //Register message forwarder which translates command to message and forward it to the message dispatcher - $this->commandBus->utilize(new ForwardToMessageDispatcherStrategy(new ToMessageTranslator())); + $this->commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); } /** - * @return InMemoryMessageDispatcher + * @return InMemoryRemoteMessageDispatcher */ protected function setUpMessageDispatcher() { $commandBus = new CommandBus(); //Translate message back to command - $commandBus->utilize(new FromMessageTranslator()); + $commandBus->utilize(new FromRemoteMessageTranslator()); $router = new CommandRouter(); @@ -89,7 +89,7 @@ protected function setUpMessageDispatcher() $commandBus->utilize(new DoSomethingInvokeStrategy()); //Set up message dispatcher with a prepared command bus that can dispatch the message to command handler - $messageDispatcher = new InMemoryMessageDispatcher($commandBus, new EventBus()); + $messageDispatcher = new InMemoryRemoteMessageDispatcher($commandBus, new EventBus()); return $messageDispatcher; } diff --git a/tests/Prooph/ServiceBusTest/EventBusTest.php b/tests/Prooph/ServiceBusTest/EventBusTest.php index 1163c3d..85b22b2 100644 --- a/tests/Prooph/ServiceBusTest/EventBusTest.php +++ b/tests/Prooph/ServiceBusTest/EventBusTest.php @@ -14,10 +14,10 @@ use Prooph\Common\ServiceLocator\ZF2\Zf2ServiceManagerProxy; use Prooph\ServiceBus\CommandBus; use Prooph\ServiceBus\EventBus; -use Prooph\ServiceBus\InvokeStrategy\ForwardToMessageDispatcherStrategy; -use Prooph\ServiceBus\Message\FromMessageTranslator; -use Prooph\ServiceBus\Message\InMemoryMessageDispatcher; -use Prooph\ServiceBus\Message\ToMessageTranslator; +use Prooph\ServiceBus\InvokeStrategy\ForwardToRemoteMessageDispatcherStrategy; +use Prooph\ServiceBus\Message\FromRemoteMessageTranslator; +use Prooph\ServiceBus\Message\InMemoryRemoteMessageDispatcher; +use Prooph\ServiceBus\Message\ProophDomainMessageToRemoteMessageTranslator; use Prooph\ServiceBus\Router\EventRouter; use Prooph\ServiceBus\ServiceLocator\ServiceLocatorProxy; use Prooph\ServiceBusTest\Mock\SomethingDone; @@ -57,18 +57,18 @@ protected function setUp() $this->eventBus->utilize($router); //Register message forwarder which translates event to message and forward it to the message dispatcher - $this->eventBus->utilize(new ForwardToMessageDispatcherStrategy(new ToMessageTranslator())); + $this->eventBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); } /** - * @return InMemoryMessageDispatcher + * @return InMemoryRemoteMessageDispatcher */ protected function setUpMessageDispatcher() { $eventBus = new EventBus(); //Translate message back to event - $eventBus->utilize(new FromMessageTranslator()); + $eventBus->utilize(new FromRemoteMessageTranslator()); $router = new EventRouter(); @@ -89,7 +89,7 @@ protected function setUpMessageDispatcher() $eventBus->utilize(new SomethingDoneInvokeStrategy()); //Set up message dispatcher with a prepared command bus that can dispatch the message to command handler - $messageDispatcher = new InMemoryMessageDispatcher(new CommandBus(), $eventBus); + $messageDispatcher = new InMemoryRemoteMessageDispatcher(new CommandBus(), $eventBus); return $messageDispatcher; } diff --git a/tests/Prooph/ServiceBusTest/Message/MessageHeaderTest.php b/tests/Prooph/ServiceBusTest/Message/MessageHeaderTest.php deleted file mode 100644 index 7707d07..0000000 --- a/tests/Prooph/ServiceBusTest/Message/MessageHeaderTest.php +++ /dev/null @@ -1,84 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 18:33 - */ - -namespace Prooph\ServiceBusTest\Message; - -use Prooph\ServiceBus\Message\MessageHeader; -use Prooph\ServiceBusTest\TestCase; -use Rhumsaa\Uuid\Uuid; - -/** - * Class MessageHeaderTest - * - * @package Prooph\ServiceBusTest\Message - * @author Alexander Miertsch - */ -class MessageHeaderTest extends TestCase -{ - /** - * @test - */ - public function it_has_a_uuid() - { - $uuid = Uuid::uuid4(); - - $header = new MessageHeader($uuid, new \DateTime(), 1, MessageHeader::TYPE_COMMAND); - - $this->assertEquals($uuid->toString(), $header->uuid()->toString()); - } - - /** - * @test - */ - public function it_has_a_created_on_datetime() - { - $createdOn = new \DateTime(); - - $header = new MessageHeader(Uuid::uuid4(), $createdOn, 1, MessageHeader::TYPE_COMMAND); - - $this->assertEquals($createdOn->getTimestamp(), $header->createdOn()->getTimestamp()); - } - - /** - * @test - */ - public function it_has_a_version() - { - $header = new MessageHeader(Uuid::uuid4(), new \DateTime(), 1, MessageHeader::TYPE_COMMAND); - - $this->assertEquals(1, $header->version()); - } - - /** - * @test - */ - public function it_has_a_type() - { - $header = new MessageHeader(Uuid::uuid4(), new \DateTime(), 1, MessageHeader::TYPE_COMMAND); - - $this->assertEquals('command', $header->type()); - } - - /** - * @test - */ - public function it_converts_itself_to_array_and_back() - { - $header = new MessageHeader(Uuid::uuid4(), new \DateTime(), 1, MessageHeader::TYPE_COMMAND); - - $headerArray = $header->toArray(); - - $sameHeader = MessageHeader::fromArray($headerArray); - - $this->assertEquals($header->toArray(), $sameHeader->toArray()); - } -} - \ No newline at end of file diff --git a/tests/Prooph/ServiceBusTest/Message/StandardMessageTest.php b/tests/Prooph/ServiceBusTest/Message/StandardMessageTest.php deleted file mode 100644 index 563e39b..0000000 --- a/tests/Prooph/ServiceBusTest/Message/StandardMessageTest.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 18:43 - */ - -namespace Prooph\ServiceBusTest\Message; - -use Prooph\ServiceBus\Message\MessageHeader; -use Prooph\ServiceBus\Message\StandardMessage; -use Prooph\ServiceBusTest\TestCase; -use Rhumsaa\Uuid\Uuid; - -/** - * Class StandardMessageTest - * - * @package Prooph\ServiceBusTest\Message - * @author Alexander Miertsch - */ -class StandardMessageTest extends TestCase -{ - /** - * @var StandardMessage - */ - private $message; - - /** - * @var MessageHeader - */ - private $header; - - protected function setUp() - { - $this->header = new MessageHeader(Uuid::uuid4(), new \DateTime(), 1, MessageHeader::TYPE_COMMAND); - - $this->message = new StandardMessage('TestMessage', $this->header, array('data' => 'a test')); - } - - /** - * @test - */ - public function it_has_a_name() - { - $this->assertEquals('TestMessage', $this->message->name()); - } - - /** - * @test - */ - public function it_has_a_header() - { - $this->assertInstanceOf('Prooph\ServiceBus\Message\MessageHeader', $this->message->header()); - } - - /** - * @test - */ - public function it_has_a_payload() - { - $this->assertEquals(array('data' => 'a test'), $this->message->payload()); - } -} - \ No newline at end of file diff --git a/tests/Prooph/ServiceBusTest/Message/ToAndFromMessageTranslatorTest.php b/tests/Prooph/ServiceBusTest/Message/ToAndFromMessageTranslatorTest.php index 0e83d87..9e4e4d8 100644 --- a/tests/Prooph/ServiceBusTest/Message/ToAndFromMessageTranslatorTest.php +++ b/tests/Prooph/ServiceBusTest/Message/ToAndFromMessageTranslatorTest.php @@ -11,8 +11,10 @@ namespace Prooph\ServiceBusTest\Message; -use Prooph\ServiceBus\Message\FromMessageTranslator; -use Prooph\ServiceBus\Message\ToMessageTranslator; +use Prooph\Common\Messaging\Command; +use Prooph\Common\Messaging\DomainEvent; +use Prooph\ServiceBus\Message\FromRemoteMessageTranslator; +use Prooph\ServiceBus\Message\ProophDomainMessageToRemoteMessageTranslator; use Prooph\ServiceBusTest\Mock\DoSomething; use Prooph\ServiceBusTest\Mock\SomethingDone; use Prooph\ServiceBusTest\TestCase; @@ -30,26 +32,26 @@ class ToAndFromMessageTranslatorTest extends TestCase */ public function it_translates_command_to_and_from_message() { - $toMessageTranslator = new ToMessageTranslator(); + $toMessageTranslator = new ProophDomainMessageToRemoteMessageTranslator(); $doSomething = DoSomething::fromData('test command'); - $this->assertTrue($toMessageTranslator->canTranslateToMessage($doSomething)); + $this->assertTrue($toMessageTranslator->canTranslateToRemoteMessage($doSomething)); - $message = $toMessageTranslator->translateToMessage($doSomething); + $message = $toMessageTranslator->translateToRemoteMessage($doSomething); $this->assertEquals(array('data' => 'test command'), $message->payload()); - $fromMessageTranslator = new FromMessageTranslator(); + $fromMessageTranslator = new FromRemoteMessageTranslator(); - $command = $fromMessageTranslator->translateFromMessage($message); + $command = $fromMessageTranslator->translateFromRemoteMessage($message); - $this->assertInstanceOf('Prooph\ServiceBus\Command', $command); - $this->assertEquals($doSomething->getMessageName(), $command->getMessageName()); + $this->assertInstanceOf(Command::class, $command); + $this->assertEquals($doSomething->messageName(), $command->messageName()); $this->assertEquals($doSomething->payload(), $command->payload()); $this->assertEquals($doSomething->uuid()->toString(), $command->uuid()->toString()); $this->assertEquals($doSomething->version(), $command->version()); - $this->assertEquals($doSomething->createdOn()->format(\DateTime::ISO8601), $command->createdOn()->format(\DateTime::ISO8601)); + $this->assertEquals($doSomething->createdAt()->format(\DateTime::ISO8601), $command->createdAt()->format(\DateTime::ISO8601)); } /** @@ -57,26 +59,26 @@ public function it_translates_command_to_and_from_message() */ public function it_translates_event_to_and_from_message() { - $toMessageTranslator = new ToMessageTranslator(); + $toMessageTranslator = new ProophDomainMessageToRemoteMessageTranslator(); $somethingDone = SomethingDone::fromData('test event'); - $this->assertTrue($toMessageTranslator->canTranslateToMessage($somethingDone)); + $this->assertTrue($toMessageTranslator->canTranslateToRemoteMessage($somethingDone)); - $message = $toMessageTranslator->translateToMessage($somethingDone); + $message = $toMessageTranslator->translateToRemoteMessage($somethingDone); $this->assertEquals(array('data' => 'test event'), $message->payload()); - $fromMessageTranslator = new FromMessageTranslator(); + $fromMessageTranslator = new FromRemoteMessageTranslator(); - $event = $fromMessageTranslator->translateFromMessage($message); + $event = $fromMessageTranslator->translateFromRemoteMessage($message); - $this->assertInstanceOf('Prooph\ServiceBus\Event', $event); - $this->assertEquals($somethingDone->getMessageName(), $event->getMessageName()); + $this->assertInstanceOf(DomainEvent::class, $event); + $this->assertEquals($somethingDone->messageName(), $event->messageName()); $this->assertEquals($somethingDone->payload(), $event->payload()); $this->assertEquals($somethingDone->uuid()->toString(), $event->uuid()->toString()); $this->assertEquals($somethingDone->version(), $event->version()); - $this->assertEquals($somethingDone->occurredOn()->format(\DateTime::ISO8601), $event->occurredOn()->format(\DateTime::ISO8601)); + $this->assertEquals($somethingDone->createdAt()->format(\DateTime::ISO8601), $event->createdAt()->format(\DateTime::ISO8601)); } } \ No newline at end of file diff --git a/tests/Prooph/ServiceBusTest/Mock/DoSomething.php b/tests/Prooph/ServiceBusTest/Mock/DoSomething.php index decd099..d695591 100644 --- a/tests/Prooph/ServiceBusTest/Mock/DoSomething.php +++ b/tests/Prooph/ServiceBusTest/Mock/DoSomething.php @@ -11,7 +11,8 @@ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Command; +use Prooph\Common\Messaging\Command; + /** * Class DoSomething diff --git a/tests/Prooph/ServiceBusTest/Mock/DoSomethingHandler.php b/tests/Prooph/ServiceBusTest/Mock/DoSomethingHandler.php index 8103fae..fd8576e 100644 --- a/tests/Prooph/ServiceBusTest/Mock/DoSomethingHandler.php +++ b/tests/Prooph/ServiceBusTest/Mock/DoSomethingHandler.php @@ -10,7 +10,7 @@ */ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Command; +use Prooph\Common\Messaging\Command; /** * Class DoSomethingHandler diff --git a/tests/Prooph/ServiceBusTest/Mock/DoSomethingInvokeStrategy.php b/tests/Prooph/ServiceBusTest/Mock/DoSomethingInvokeStrategy.php index a8fd9dd..4d2e320 100644 --- a/tests/Prooph/ServiceBusTest/Mock/DoSomethingInvokeStrategy.php +++ b/tests/Prooph/ServiceBusTest/Mock/DoSomethingInvokeStrategy.php @@ -10,7 +10,8 @@ */ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Command; + +use Prooph\Common\Messaging\Command; use Prooph\ServiceBus\InvokeStrategy\AbstractInvokeStrategy; /** diff --git a/tests/Prooph/ServiceBusTest/Mock/OnEventHandler.php b/tests/Prooph/ServiceBusTest/Mock/OnEventHandler.php index a1876be..77cd477 100644 --- a/tests/Prooph/ServiceBusTest/Mock/OnEventHandler.php +++ b/tests/Prooph/ServiceBusTest/Mock/OnEventHandler.php @@ -11,8 +11,6 @@ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Event\EventInterface; - /** * Class OnEventHandler * diff --git a/tests/Prooph/ServiceBusTest/Mock/PayloadMockObject.php b/tests/Prooph/ServiceBusTest/Mock/PayloadMockObject.php deleted file mode 100644 index 01eafb2..0000000 --- a/tests/Prooph/ServiceBusTest/Mock/PayloadMockObject.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 11.03.14 - 21:18 - */ - -namespace Prooph\ServiceBusTest\Mock; - -use Prooph\ServiceBus\Message\PayloadInterface; - -/** - * Class PayloadMockObject - * - * @package Prooph\ServiceBusTest\Mock - * @author Alexander Miertsch - */ -class PayloadMockObject implements PayloadInterface -{ - /** - * @var array - */ - private $payload = array(); - - /** - * @param array $aPayload - */ - public function __construct(array $aPayload) - { - $this->payload = $aPayload; - } - - /** - * @return array - */ - public function getArrayCopy() - { - return $this->payload; - } -} - \ No newline at end of file diff --git a/tests/Prooph/ServiceBusTest/Mock/SomethingDone.php b/tests/Prooph/ServiceBusTest/Mock/SomethingDone.php index a88d9ff..22f0e77 100644 --- a/tests/Prooph/ServiceBusTest/Mock/SomethingDone.php +++ b/tests/Prooph/ServiceBusTest/Mock/SomethingDone.php @@ -11,7 +11,7 @@ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Event; +use Prooph\Common\Messaging\DomainEvent; /** * Class SomethingDone @@ -19,7 +19,7 @@ * @package Prooph\ServiceBusTest\Mock * @author Alexander Miertsch */ -class SomethingDone extends Event +class SomethingDone extends DomainEvent { /** * @param string $dataString diff --git a/tests/Prooph/ServiceBusTest/Mock/SomethingDoneInvokeStrategy.php b/tests/Prooph/ServiceBusTest/Mock/SomethingDoneInvokeStrategy.php index 6e0691e..e796d30 100644 --- a/tests/Prooph/ServiceBusTest/Mock/SomethingDoneInvokeStrategy.php +++ b/tests/Prooph/ServiceBusTest/Mock/SomethingDoneInvokeStrategy.php @@ -10,7 +10,8 @@ */ namespace Prooph\ServiceBusTest\Mock; -use Prooph\ServiceBus\Event; + +use Prooph\Common\Messaging\DomainEvent; use Prooph\ServiceBus\InvokeStrategy\AbstractInvokeStrategy; /** @@ -28,7 +29,7 @@ class SomethingDoneInvokeStrategy extends AbstractInvokeStrategy */ public function canInvoke($aHandler, $aCommandOrEvent) { - return $aHandler instanceof SomethingDoneListener && $aCommandOrEvent instanceof Event; + return $aHandler instanceof SomethingDoneListener && $aCommandOrEvent instanceof DomainEvent; } /** diff --git a/tests/Prooph/ServiceBusTest/Mock/SomethingDoneListener.php b/tests/Prooph/ServiceBusTest/Mock/SomethingDoneListener.php index d6dc9e7..b3bfa23 100644 --- a/tests/Prooph/ServiceBusTest/Mock/SomethingDoneListener.php +++ b/tests/Prooph/ServiceBusTest/Mock/SomethingDoneListener.php @@ -10,8 +10,7 @@ */ namespace Prooph\ServiceBusTest\Mock; - -use Prooph\ServiceBus\Event; +use Prooph\Common\Messaging\DomainEvent; /** * Class SomethingDoneListener @@ -27,15 +26,15 @@ class SomethingDoneListener private $lastEvent; /** - * @param Event $event + * @param DomainEvent $event */ - public function somethingDone(Event $event) + public function somethingDone(DomainEvent $event) { $this->lastEvent = $event; } /** - * @return Event + * @return DomainEvent */ public function lastEvent() { diff --git a/tests/Prooph/ServiceBusTest/Router/CommandRouterTest.php b/tests/Prooph/ServiceBusTest/Router/CommandRouterTest.php index 334f699..4a50a22 100644 --- a/tests/Prooph/ServiceBusTest/Router/CommandRouterTest.php +++ b/tests/Prooph/ServiceBusTest/Router/CommandRouterTest.php @@ -33,7 +33,7 @@ public function it_can_handle_routing_definition_by_chaining_route_to() $router->route('Prooph\ServiceBusTest\Mock\DoSomething')->to("DoSomethingHandler"); - $commandDispatch = CommandDispatch::initializeWith(DoSomething::getNew(), new CommandBus()); + $commandDispatch = CommandDispatch::initializeWith(DoSomething::fromData([]), new CommandBus()); $commandDispatch->setName(CommandDispatch::ROUTE); @@ -77,7 +77,7 @@ public function it_takes_a_routing_definition_on_instantiation() 'Prooph\ServiceBusTest\Mock\DoSomething' => 'DoSomethingHandler' )); - $commandDispatch = CommandDispatch::initializeWith(DoSomething::getNew(), new CommandBus()); + $commandDispatch = CommandDispatch::initializeWith(DoSomething::fromData([]), new CommandBus()); $commandDispatch->setName(CommandDispatch::ROUTE); diff --git a/tests/Prooph/ServiceBusTest/Router/EventRouterTest.php b/tests/Prooph/ServiceBusTest/Router/EventRouterTest.php index 01c5920..58dd4ca 100644 --- a/tests/Prooph/ServiceBusTest/Router/EventRouterTest.php +++ b/tests/Prooph/ServiceBusTest/Router/EventRouterTest.php @@ -34,7 +34,7 @@ public function it_can_handle_routing_definition_by_chaining_route_to() $router->route('Prooph\ServiceBusTest\Mock\SomethingDone')->to("SomethingDoneListener"); - $eventDispatch = EventDispatch::initializeWith(SomethingDone::getNew(), new EventBus()); + $eventDispatch = EventDispatch::initializeWith(SomethingDone::fromData([]), new EventBus()); $eventDispatch->setName(EventDispatch::ROUTE); @@ -93,7 +93,7 @@ public function it_takes_a_routing_definition_with_a_single_listener_on_instanti 'Prooph\ServiceBusTest\Mock\SomethingDone' => 'SomethingDoneListener' )); - $eventDispatch = EventDispatch::initializeWith(SomethingDone::getNew(), new EventBus()); + $eventDispatch = EventDispatch::initializeWith(SomethingDone::fromData([]), new EventBus()); $eventDispatch->setName(EventDispatch::ROUTE); @@ -111,7 +111,7 @@ public function it_takes_a_routing_definition_with_a_multiple_listeners_on_insta 'Prooph\ServiceBusTest\Mock\SomethingDone' => ['SomethingDoneListener1', 'SomethingDoneListener2'] )); - $eventDispatch = EventDispatch::initializeWith(SomethingDone::getNew(), new EventBus()); + $eventDispatch = EventDispatch::initializeWith(SomethingDone::fromData([]), new EventBus()); $eventDispatch->setName(EventDispatch::ROUTE); diff --git a/tests/Prooph/ServiceBusTest/Router/RegexRouterTest.php b/tests/Prooph/ServiceBusTest/Router/RegexRouterTest.php index dc99813..2064b6a 100644 --- a/tests/Prooph/ServiceBusTest/Router/RegexRouterTest.php +++ b/tests/Prooph/ServiceBusTest/Router/RegexRouterTest.php @@ -37,7 +37,7 @@ public function it_matches_pattern_with_command_name_to_detect_appropriate_handl $regexRouter->route('/^'.preg_quote('Prooph\ServiceBusTest\Mock\Do').'.*/')->to("DoSomethingHandler"); - $commandDispatch = CommandDispatch::initializeWith(DoSomething::getNew(), new CommandBus()); + $commandDispatch = CommandDispatch::initializeWith(DoSomething::fromData([]), new CommandBus()); $commandDispatch->setName(CommandDispatch::ROUTE); @@ -58,7 +58,7 @@ public function it_does_not_allow_that_two_pattern_matches_with_same_command_nam $this->setExpectedException('\Prooph\ServiceBus\Exception\RuntimeException'); - $commandDispatch = CommandDispatch::initializeWith(DoSomething::getNew(), new CommandBus()); + $commandDispatch = CommandDispatch::initializeWith(DoSomething::fromData([]), new CommandBus()); $commandDispatch->setName(CommandDispatch::ROUTE); @@ -75,7 +75,7 @@ public function it_matches_pattern_with_event_name_and_routes_to_multiple_listen $regexRouter->route('/^'.preg_quote('Prooph\ServiceBusTest\Mock\\').'.*Done$/')->to("SomethingDoneListener1"); $regexRouter->route('/^'.preg_quote('Prooph\ServiceBusTest\Mock\\').'.*Done$/')->to("SomethingDoneListener2"); - $eventDispatch = EventDispatch::initializeWith(SomethingDone::getNew(), new EventBus()); + $eventDispatch = EventDispatch::initializeWith(SomethingDone::fromData([]), new EventBus()); $eventDispatch->setName(EventDispatch::ROUTE); @@ -121,7 +121,7 @@ public function it_takes_a_routing_definition_on_instantiation() )); - $commandDispatch = CommandDispatch::initializeWith(DoSomething::getNew(), new CommandBus()); + $commandDispatch = CommandDispatch::initializeWith(DoSomething::fromData([]), new CommandBus()); $commandDispatch->setName(CommandDispatch::ROUTE); @@ -129,7 +129,7 @@ public function it_takes_a_routing_definition_on_instantiation() $this->assertEquals("DoSomethingHandler", $commandDispatch->getCommandHandler()); - $eventDispatch = EventDispatch::initializeWith(SomethingDone::getNew(), new EventBus()); + $eventDispatch = EventDispatch::initializeWith(SomethingDone::fromData([]), new EventBus()); $eventDispatch->setName(EventDispatch::ROUTE);