diff --git a/LICENSE.txt b/LICENSE.txt index 0f30df1..a7200a7 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,5 @@ -Copyright (c) 2013, Alexander Miertsch contact@prooph.de +Copyright (c) 2013-2017, prooph software GmbH +Copyright (c) 2015-2017, Sascha-Oliver Prolic All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/config/prooph_service_bus.config.php b/config/prooph_service_bus.config.php index 26bf26c..4e52412 100644 --- a/config/prooph_service_bus.config.php +++ b/config/prooph_service_bus.config.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/config/services.php b/config/services.php index 86a7f8f..09a0396 100644 --- a/config/services.php +++ b/config/services.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/examples/quick-start.php b/examples/quick-start.php index a0bb967..b597c34 100644 --- a/examples/quick-start.php +++ b/examples/quick-start.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Async/AsyncMessage.php b/src/Async/AsyncMessage.php index 16137c4..64ff33d 100644 --- a/src/Async/AsyncMessage.php +++ b/src/Async/AsyncMessage.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Async/MessageProducer.php b/src/Async/MessageProducer.php index d09890b..6cdb9a9 100644 --- a/src/Async/MessageProducer.php +++ b/src/Async/MessageProducer.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/CommandBus.php b/src/CommandBus.php index 84efe2b..80fd0c6 100644 --- a/src/CommandBus.php +++ b/src/CommandBus.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/AbstractBusFactory.php b/src/Container/AbstractBusFactory.php index 5ba6f5f..3ef462d 100644 --- a/src/Container/AbstractBusFactory.php +++ b/src/Container/AbstractBusFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/CommandBusFactory.php b/src/Container/CommandBusFactory.php index 5cfad31..82b0d9c 100644 --- a/src/Container/CommandBusFactory.php +++ b/src/Container/CommandBusFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/EventBusFactory.php b/src/Container/EventBusFactory.php index 922d35f..1d7d236 100644 --- a/src/Container/EventBusFactory.php +++ b/src/Container/EventBusFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/Plugin/Guard/FinalizeGuardFactory.php b/src/Container/Plugin/Guard/FinalizeGuardFactory.php index 0a05f4f..a2ed120 100644 --- a/src/Container/Plugin/Guard/FinalizeGuardFactory.php +++ b/src/Container/Plugin/Guard/FinalizeGuardFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/Plugin/Guard/RouteGuardFactory.php b/src/Container/Plugin/Guard/RouteGuardFactory.php index 2439304..e2247e7 100644 --- a/src/Container/Plugin/Guard/RouteGuardFactory.php +++ b/src/Container/Plugin/Guard/RouteGuardFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Container/QueryBusFactory.php b/src/Container/QueryBusFactory.php index ee84799..72e3752 100644 --- a/src/Container/QueryBusFactory.php +++ b/src/Container/QueryBusFactory.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/EventBus.php b/src/EventBus.php index 7b4a125..f387c1c 100644 --- a/src/EventBus.php +++ b/src/EventBus.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Exception/CommandDispatchException.php b/src/Exception/CommandDispatchException.php index f1210d9..021ee33 100644 --- a/src/Exception/CommandDispatchException.php +++ b/src/Exception/CommandDispatchException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 09dc7fd..04300ed 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Exception/MessageDispatchException.php b/src/Exception/MessageDispatchException.php index 25f1db9..dafa90d 100644 --- a/src/Exception/MessageDispatchException.php +++ b/src/Exception/MessageDispatchException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 28ae8ce..8344648 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Exception/ServiceBusException.php b/src/Exception/ServiceBusException.php index 5f2813a..dcd913a 100644 --- a/src/Exception/ServiceBusException.php +++ b/src/Exception/ServiceBusException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/MessageBus.php b/src/MessageBus.php index a430b01..d6f76a9 100644 --- a/src/MessageBus.php +++ b/src/MessageBus.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php index 0ab4049..fe85845 100644 --- a/src/Plugin/AbstractPlugin.php +++ b/src/Plugin/AbstractPlugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Guard/AuthorizationService.php b/src/Plugin/Guard/AuthorizationService.php index aaaac79..4b559e2 100644 --- a/src/Plugin/Guard/AuthorizationService.php +++ b/src/Plugin/Guard/AuthorizationService.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Guard/FinalizeGuard.php b/src/Plugin/Guard/FinalizeGuard.php index 064ee4c..daf75e3 100644 --- a/src/Plugin/Guard/FinalizeGuard.php +++ b/src/Plugin/Guard/FinalizeGuard.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Guard/RouteGuard.php b/src/Plugin/Guard/RouteGuard.php index 1371121..a7aa0fb 100644 --- a/src/Plugin/Guard/RouteGuard.php +++ b/src/Plugin/Guard/RouteGuard.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Guard/UnauthorizedException.php b/src/Plugin/Guard/UnauthorizedException.php index 9fa7ed4..a7d3b4a 100644 --- a/src/Plugin/Guard/UnauthorizedException.php +++ b/src/Plugin/Guard/UnauthorizedException.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php b/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php index ab15562..300b33a 100644 --- a/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php +++ b/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php b/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php index 209a146..673359d 100644 --- a/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php +++ b/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/InvokeStrategy/HandleCommandStrategy.php b/src/Plugin/InvokeStrategy/HandleCommandStrategy.php index 2055aa4..a29125a 100644 --- a/src/Plugin/InvokeStrategy/HandleCommandStrategy.php +++ b/src/Plugin/InvokeStrategy/HandleCommandStrategy.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/InvokeStrategy/OnEventStrategy.php b/src/Plugin/InvokeStrategy/OnEventStrategy.php index 825778a..61f237f 100644 --- a/src/Plugin/InvokeStrategy/OnEventStrategy.php +++ b/src/Plugin/InvokeStrategy/OnEventStrategy.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,14 +12,28 @@ namespace Prooph\ServiceBus\Plugin\InvokeStrategy; -class OnEventStrategy extends AbstractInvokeStrategy +use Prooph\Common\Event\ActionEvent; +use Prooph\ServiceBus\EventBus; +use Prooph\ServiceBus\MessageBus; +use Prooph\ServiceBus\Plugin\AbstractPlugin; + +final class OnEventStrategy extends AbstractPlugin { - /** - * @param mixed $handler - * @param mixed $message - */ - public function invoke($handler, $message): void + public function attachToMessageBus(MessageBus $messageBus): void { - $handler->onEvent($message); + $this->listenerHandlers[] = $messageBus->attach( + MessageBus::EVENT_DISPATCH, + function (ActionEvent $actionEvent): void { + $message = $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE); + $handlers = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS); + + foreach ($handlers as $handler) { + $handler->onEvent($message); + } + + $actionEvent->setParam(MessageBus::EVENT_PARAM_MESSAGE_HANDLED, true); + }, + MessageBus::PRIORITY_INVOKE_HANDLER + ); } } diff --git a/src/Plugin/MessageFactoryPlugin.php b/src/Plugin/MessageFactoryPlugin.php index 1174b73..a57fe66 100644 --- a/src/Plugin/MessageFactoryPlugin.php +++ b/src/Plugin/MessageFactoryPlugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/MessageProducerPlugin.php b/src/Plugin/MessageProducerPlugin.php index fd7cd4c..20576ab 100644 --- a/src/Plugin/MessageProducerPlugin.php +++ b/src/Plugin/MessageProducerPlugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index 919e2c0..57bd827 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/AsyncSwitchMessageRouter.php b/src/Plugin/Router/AsyncSwitchMessageRouter.php index 65e45db..e880c26 100644 --- a/src/Plugin/Router/AsyncSwitchMessageRouter.php +++ b/src/Plugin/Router/AsyncSwitchMessageRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/CommandRouter.php b/src/Plugin/Router/CommandRouter.php index c1e716a..ee61a14 100644 --- a/src/Plugin/Router/CommandRouter.php +++ b/src/Plugin/Router/CommandRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/EventRouter.php b/src/Plugin/Router/EventRouter.php index 2491fb7..3dc1d93 100644 --- a/src/Plugin/Router/EventRouter.php +++ b/src/Plugin/Router/EventRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/MessageBusRouterPlugin.php b/src/Plugin/Router/MessageBusRouterPlugin.php index 2b7130c..5c7ab5b 100644 --- a/src/Plugin/Router/MessageBusRouterPlugin.php +++ b/src/Plugin/Router/MessageBusRouterPlugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/QueryRouter.php b/src/Plugin/Router/QueryRouter.php index ec1a3b0..1829794 100644 --- a/src/Plugin/Router/QueryRouter.php +++ b/src/Plugin/Router/QueryRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/RegexRouter.php b/src/Plugin/Router/RegexRouter.php index 002728a..cadc33c 100644 --- a/src/Plugin/Router/RegexRouter.php +++ b/src/Plugin/Router/RegexRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/ServiceLocatorEventRouter.php b/src/Plugin/Router/ServiceLocatorEventRouter.php index 14827b6..da59ad3 100644 --- a/src/Plugin/Router/ServiceLocatorEventRouter.php +++ b/src/Plugin/Router/ServiceLocatorEventRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/SingleHandlerRouter.php b/src/Plugin/Router/SingleHandlerRouter.php index 117dc64..bd764c0 100644 --- a/src/Plugin/Router/SingleHandlerRouter.php +++ b/src/Plugin/Router/SingleHandlerRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/Router/SingleHandlerServiceLocatorRouter.php b/src/Plugin/Router/SingleHandlerServiceLocatorRouter.php index 5ce75d1..046d6c1 100644 --- a/src/Plugin/Router/SingleHandlerServiceLocatorRouter.php +++ b/src/Plugin/Router/SingleHandlerServiceLocatorRouter.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Plugin/ServiceLocatorPlugin.php b/src/Plugin/ServiceLocatorPlugin.php index 1a4609b..92c0972 100644 --- a/src/Plugin/ServiceLocatorPlugin.php +++ b/src/Plugin/ServiceLocatorPlugin.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/QueryBus.php b/src/QueryBus.php index 6abc4b4..dc940af 100644 --- a/src/QueryBus.php +++ b/src/QueryBus.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/CommandBusTest.php b/tests/CommandBusTest.php index 6ed243f..75a03c5 100644 --- a/tests/CommandBusTest.php +++ b/tests/CommandBusTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Container/BusFactoriesTest.php b/tests/Container/BusFactoriesTest.php index 05ddd3c..26bd378 100644 --- a/tests/Container/BusFactoriesTest.php +++ b/tests/Container/BusFactoriesTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Container/Plugin/Guard/FinalizeGuardFactoryTest.php b/tests/Container/Plugin/Guard/FinalizeGuardFactoryTest.php index c439153..c68d135 100644 --- a/tests/Container/Plugin/Guard/FinalizeGuardFactoryTest.php +++ b/tests/Container/Plugin/Guard/FinalizeGuardFactoryTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Container/Plugin/Guard/RouteGuardFactoryTest.php b/tests/Container/Plugin/Guard/RouteGuardFactoryTest.php index 9085497..4a4786c 100644 --- a/tests/Container/Plugin/Guard/RouteGuardFactoryTest.php +++ b/tests/Container/Plugin/Guard/RouteGuardFactoryTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/EventBusTest.php b/tests/EventBusTest.php index 4180cff..f78d86c 100644 --- a/tests/EventBusTest.php +++ b/tests/EventBusTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Exception/CommandDispatchExceptionTest.php b/tests/Exception/CommandDispatchExceptionTest.php index 2806f92..1a3d8e6 100644 --- a/tests/Exception/CommandDispatchExceptionTest.php +++ b/tests/Exception/CommandDispatchExceptionTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/MessageBusTest.php b/tests/MessageBusTest.php index dd78d63..7cd5a21 100644 --- a/tests/MessageBusTest.php +++ b/tests/MessageBusTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/AsyncCommand.php b/tests/Mock/AsyncCommand.php index 192a7a7..7a1fa9d 100644 --- a/tests/Mock/AsyncCommand.php +++ b/tests/Mock/AsyncCommand.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/AsyncEvent.php b/tests/Mock/AsyncEvent.php index eabc2b2..2cf90cc 100644 --- a/tests/Mock/AsyncEvent.php +++ b/tests/Mock/AsyncEvent.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/CustomMessage.php b/tests/Mock/CustomMessage.php index a716160..24a8e51 100644 --- a/tests/Mock/CustomMessage.php +++ b/tests/Mock/CustomMessage.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/CustomMessageBus.php b/tests/Mock/CustomMessageBus.php index a38fe41..8e241c5 100644 --- a/tests/Mock/CustomMessageBus.php +++ b/tests/Mock/CustomMessageBus.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/CustomMessageCommandHandler.php b/tests/Mock/CustomMessageCommandHandler.php index 4f5c0d0..9c2d9ba 100644 --- a/tests/Mock/CustomMessageCommandHandler.php +++ b/tests/Mock/CustomMessageCommandHandler.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/CustomMessageEventHandler.php b/tests/Mock/CustomMessageEventHandler.php new file mode 100644 index 0000000..becf36f --- /dev/null +++ b/tests/Mock/CustomMessageEventHandler.php @@ -0,0 +1,36 @@ + + * (c) 2015-2017 Sascha-Oliver Prolic + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ProophTest\ServiceBus\Mock; + +final class CustomMessageEventHandler +{ + private $lastMessage; + + private $invokeCounter = 0; + + public function onEvent($message): void + { + $this->lastMessage = $message; + $this->invokeCounter++; + } + + public function getLastMessage() + { + return $this->lastMessage; + } + + public function getInvokeCounter(): int + { + return $this->invokeCounter; + } +} diff --git a/tests/Mock/CustomMessageWithName.php b/tests/Mock/CustomMessageWithName.php index 43f67a5..0ecf64b 100644 --- a/tests/Mock/CustomMessageWithName.php +++ b/tests/Mock/CustomMessageWithName.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/DoSomething.php b/tests/Mock/DoSomething.php index 0623a8d..f168bf1 100644 --- a/tests/Mock/DoSomething.php +++ b/tests/Mock/DoSomething.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/ErrorProducer.php b/tests/Mock/ErrorProducer.php index b70b5ca..09dcfa4 100644 --- a/tests/Mock/ErrorProducer.php +++ b/tests/Mock/ErrorProducer.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/FetchSomething.php b/tests/Mock/FetchSomething.php index 3907896..5d576ab 100644 --- a/tests/Mock/FetchSomething.php +++ b/tests/Mock/FetchSomething.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/Finder.php b/tests/Mock/Finder.php index 6046d00..b5e7261 100644 --- a/tests/Mock/Finder.php +++ b/tests/Mock/Finder.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/MessageHandler.php b/tests/Mock/MessageHandler.php index 6a77264..ba041e2 100644 --- a/tests/Mock/MessageHandler.php +++ b/tests/Mock/MessageHandler.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/NonAsyncCommand.php b/tests/Mock/NonAsyncCommand.php index e9be60e..1deae2b 100644 --- a/tests/Mock/NonAsyncCommand.php +++ b/tests/Mock/NonAsyncCommand.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/NoopMessageProducer.php b/tests/Mock/NoopMessageProducer.php index 6c0d25d..7673335 100644 --- a/tests/Mock/NoopMessageProducer.php +++ b/tests/Mock/NoopMessageProducer.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Mock/SomethingDone.php b/tests/Mock/SomethingDone.php index f1f1a96..509b04b 100644 --- a/tests/Mock/SomethingDone.php +++ b/tests/Mock/SomethingDone.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Guard/FinalizeGuardTest.php b/tests/Plugin/Guard/FinalizeGuardTest.php index 91e8cec..7e145bd 100644 --- a/tests/Plugin/Guard/FinalizeGuardTest.php +++ b/tests/Plugin/Guard/FinalizeGuardTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Guard/RouteGuardTest.php b/tests/Plugin/Guard/RouteGuardTest.php index b2df65c..3f3aa7f 100644 --- a/tests/Plugin/Guard/RouteGuardTest.php +++ b/tests/Plugin/Guard/RouteGuardTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php b/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php index f87181b..096b268 100644 --- a/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php b/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php index 7cb46de..d0d8815 100644 --- a/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php b/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php index 2420b55..e2fa813 100644 --- a/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,9 +13,13 @@ namespace ProophTest\ServiceBus\Plugin\InvokeStrategy; use PHPUnit\Framework\TestCase; +use Prooph\Common\Event\DefaultListenerHandler; +use Prooph\ServiceBus\EventBus; use Prooph\ServiceBus\Plugin\InvokeStrategy\OnEventStrategy; +use Prooph\ServiceBus\Plugin\Router\EventRouter; use ProophTest\ServiceBus\Mock\CustomMessage; -use ProophTest\ServiceBus\Mock\MessageHandler; +use ProophTest\ServiceBus\Mock\CustomMessageEventHandler; +use Prophecy\Argument; class OnEventStrategyTest extends TestCase { @@ -24,14 +28,42 @@ class OnEventStrategyTest extends TestCase */ public function it_invokes_the_on_event_method_of_the_handler(): void { + $eventBus = new EventBus(); + $onEventStrategy = new OnEventStrategy(); + $onEventStrategy->attachToMessageBus($eventBus); - $customEvent = new CustomMessage('I am an event'); + $onEventHandler = new CustomMessageEventHandler(); - $onEventHandler = new MessageHandler(); + $eventRouter = new EventRouter([ + 'ProophTest\ServiceBus\Mock\CustomMessage' => $onEventHandler, + ]); + $eventRouter->attachToMessageBus($eventBus); - $onEventStrategy->invoke($onEventHandler, $customEvent); + $customEvent = new CustomMessage('I am an event'); + $eventBus->dispatch($customEvent); $this->assertSame($customEvent, $onEventHandler->getLastMessage()); + $this->assertSame(1, $onEventHandler->getInvokeCounter()); + } + + /** + * @test + */ + public function it_can_be_attached_to_event_bus(): void + { + $onEventStrategy = new OnEventStrategy(); + + $bus = $this->prophesize(EventBus::class); + $bus->attach(Argument::type('string'), Argument::type('callable'), Argument::type('integer')) + ->shouldBeCalled() + ->willReturn( + new DefaultListenerHandler( + function () { + } + ) + ); + + $onEventStrategy->attachToMessageBus($bus->reveal()); } } diff --git a/tests/Plugin/MessageFactoryPluginTest.php b/tests/Plugin/MessageFactoryPluginTest.php index 6b4d497..268d6a6 100644 --- a/tests/Plugin/MessageFactoryPluginTest.php +++ b/tests/Plugin/MessageFactoryPluginTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/MessageProducerPluginTest.php b/tests/Plugin/MessageProducerPluginTest.php index 90e307d..3b55034 100644 --- a/tests/Plugin/MessageProducerPluginTest.php +++ b/tests/Plugin/MessageProducerPluginTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/AsyncSwitchMessageRouterTest.php b/tests/Plugin/Router/AsyncSwitchMessageRouterTest.php index 39e0f81..03f19cf 100644 --- a/tests/Plugin/Router/AsyncSwitchMessageRouterTest.php +++ b/tests/Plugin/Router/AsyncSwitchMessageRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/EventRouterTest.php b/tests/Plugin/Router/EventRouterTest.php index d8312c8..468b18e 100644 --- a/tests/Plugin/Router/EventRouterTest.php +++ b/tests/Plugin/Router/EventRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/RegexRouterTest.php b/tests/Plugin/Router/RegexRouterTest.php index c81d956..7aa16ac 100644 --- a/tests/Plugin/Router/RegexRouterTest.php +++ b/tests/Plugin/Router/RegexRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/ServiceLocatorEventRouterTest.php b/tests/Plugin/Router/ServiceLocatorEventRouterTest.php index 6a73d19..e03f524 100644 --- a/tests/Plugin/Router/ServiceLocatorEventRouterTest.php +++ b/tests/Plugin/Router/ServiceLocatorEventRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/SingleHandlerRouterTest.php b/tests/Plugin/Router/SingleHandlerRouterTest.php index 920244b..fc41b76 100644 --- a/tests/Plugin/Router/SingleHandlerRouterTest.php +++ b/tests/Plugin/Router/SingleHandlerRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/Router/SingleHandlerServiceLocatorRouterTest.php b/tests/Plugin/Router/SingleHandlerServiceLocatorRouterTest.php index 6cca247..8631065 100644 --- a/tests/Plugin/Router/SingleHandlerServiceLocatorRouterTest.php +++ b/tests/Plugin/Router/SingleHandlerServiceLocatorRouterTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/Plugin/ServiceLocatorPluginTest.php b/tests/Plugin/ServiceLocatorPluginTest.php index 43e4ff3..1999bdc 100644 --- a/tests/Plugin/ServiceLocatorPluginTest.php +++ b/tests/Plugin/ServiceLocatorPluginTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/QueryBusTest.php b/tests/QueryBusTest.php index 1b76728..0030d0b 100644 --- a/tests/QueryBusTest.php +++ b/tests/QueryBusTest.php @@ -1,8 +1,8 @@ - * (c) 2015-2016 Sascha-Oliver Prolic + * (c) 2014-2017 prooph software GmbH + * (c) 2015-2017 Sascha-Oliver Prolic * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code.