Skip to content

Commit 0b483a1

Browse files
authored
Merge pull request #10 from mablae/prooph_v7
WIP: Bump service bus package
2 parents f97bfe9 + b7f97d6 commit 0b483a1

16 files changed

+184
-58
lines changed

.travis.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ cache:
1414
matrix:
1515
fast_finish: true
1616
include:
17-
- php: 7
17+
- php: 7.1
1818
env:
19+
- DEPENDENCIES=""
1920
- EXECUTE_CS_CHECK=true
20-
- EXECUTE_TEST_COVERALLS=true
21+
- TEST_COVERAGE=true
2122

2223
before_install:
2324
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
@@ -29,14 +30,11 @@ install:
2930
- composer info -i
3031

3132
script:
32-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then php ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml ; fi
33-
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
34-
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
33+
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi
34+
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi
3535

3636
after_script:
37-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
38-
- wget https://scrutinizer-ci.com/ocular.phar
39-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml ; fi
37+
- if [[ $TEST_COVERAGE == 'true' ]]; then php vendor/bin/coveralls -v; fi
4038

4139
notifications:
4240
webhooks:

composer.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,29 @@
5050
}
5151
},
5252
"require": {
53-
"php": "^7.0",
53+
"php": "^7.1",
5454
"symfony/config": "~2.8 || ~3.0",
5555
"symfony/dependency-injection": "~2.8 || ~3.0",
5656
"symfony/http-kernel": "~2.8 || ~3.0",
57-
"prooph/service-bus": "^5.1",
57+
"prooph/service-bus": "~6.0",
5858
"container-interop/container-interop": "^1.1"
5959
},
6060
"require-dev": {
6161
"phpunit/phpunit": "^5.3",
6262
"phpunit/php-invoker": "^1.1.4",
6363
"fabpot/php-cs-fixer": "^1.11",
6464
"bookdown/bookdown": "1.x-dev as 1.0.0",
65-
"tobiju/bookdown-bootswatch-templates": "1.0.x-dev"
65+
"prooph/bookdown-template": "^0.2.0",
66+
"satooshi/php-coveralls": "^1.0",
67+
"phpspec/prophecy": "dev-patch-1 as 1.6.2"
6668
},
6769
"suggest": {
6870
},
6971
"minimum-stability": "dev",
7072
"prefer-stable": true,
7173
"extra": {
7274
"branch-alias": {
73-
"dev-master": "1.0-dev",
74-
"dev-develop": "1.1-dev"
75+
"dev-master": "1.0-dev"
7576
}
7677
},
7778
"scripts": {
@@ -94,5 +95,11 @@
9495
"phpunit.xml*",
9596
"test"
9697
]
97-
}
98+
},
99+
"repositories": [
100+
{
101+
"type": "git",
102+
"url": "https://github.com/prolic/prophecy.git"
103+
}
104+
]
98105
}

doc/bookdown.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
],
88
"target": "./html",
99
"tocDepth": 2,
10-
"template": "../vendor/tobiju/bookdown-bootswatch-templates/templates/main.php",
11-
"copyright": "Copyright (c) 2016 <a href=\"http://getprooph.org/\" title=\"prooph software GmbH\">prooph software GmbH</a> <br/> Powered by <a href=\"https://github.com/tobiju/bookdown-bootswatch-templates\" title=\"Visit project to generate your own docs\">Bookdown Bootswatch Templates</a>"
10+
"template": "../vendor/prooph/bookdown-template/templates/main.php",
11+
"copyright": "Copyright (c) 2017 <a href=\"http://getprooph.org/\" title=\"prooph software GmbH\">prooph software GmbH</a> <br/> Powered by <a href=\"https://github.com/tobiju/bookdown-bootswatch-templates\" title=\"Visit project to generate your own docs\">Bookdown Bootswatch Templates</a>"
1212
}

src/DependencyInjection/Compiler/PluginsPass.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Prooph\Bundle\ServiceBus\DependencyInjection\Compiler;
1313

1414
use Prooph\Bundle\ServiceBus\DependencyInjection\ProophServiceBusExtension;
15-
use Symfony\Component\DependencyInjection\Reference;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1817

@@ -32,12 +31,13 @@ public function process(ContainerBuilder $container)
3231
$typePlugins = $container->findTaggedServiceIds(sprintf('prooph_service_bus.%s.plugin', $type . '_bus'));
3332
$plugins = $container->findTaggedServiceIds(sprintf('prooph_service_bus.%s.plugin', $name));
3433

35-
$plugins = array_merge($globalPlugins, $typePlugins, $plugins);
34+
$plugins = array_merge(array_keys($globalPlugins), array_keys($typePlugins), array_keys($plugins));
3635

37-
foreach ($plugins as $id => $args) {
38-
$definition = $container->findDefinition('prooph_service_bus.' . $name);
39-
$definition->addMethodCall('utilize', [new Reference($id)]);
40-
}
36+
$busDefinition = $container->getDefinition($bus);
37+
$busPlugins = $busDefinition->getArgument(2);
38+
39+
$finalPlugins = array_merge($busPlugins, $plugins);
40+
$busDefinition->replaceArgument(2, $finalPlugins);
4141
}
4242
}
4343
}

src/DependencyInjection/ProophServiceBusExtension.php

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Prooph\Bundle\ServiceBus\DependencyInjection;
1313

14+
use Prooph\Bundle\ServiceBus\Exception\RuntimeException;
1415
use Prooph\ServiceBus\CommandBus;
1516
use Prooph\ServiceBus\EventBus;
16-
use Prooph\ServiceBus\QueryBus;
1717
use Prooph\ServiceBus\Plugin\Router\CommandRouter;
1818
use Prooph\ServiceBus\Plugin\Router\EventRouter;
1919
use Prooph\ServiceBus\Plugin\Router\QueryRouter;
20+
use Prooph\ServiceBus\QueryBus;
2021
use Symfony\Component\Config\FileLocator;
2122
use Symfony\Component\DependencyInjection\ContainerBuilder;
2223
use Symfony\Component\DependencyInjection\DefinitionDecorator;
@@ -50,7 +51,6 @@ public function load(array $configs, ContainerBuilder $container)
5051
$configuration = $this->getConfiguration($configs, $container);
5152
$config = $this->processConfiguration($configuration, $configs);
5253

53-
5454
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
5555
$loader->load('service_bus.xml');
5656

@@ -92,7 +92,7 @@ private function busLoad(
9292

9393
$serviceBuses = [];
9494
foreach (array_keys($config) as $name) {
95-
$serviceBuses[$name] = sprintf('prooph_service_bus.%s', $name);
95+
$serviceBuses[$name] = 'prooph_service_bus.' . $name;
9696
}
9797
$container->setParameter('prooph_service_bus.' . $type . '_buses', $serviceBuses);
9898

@@ -118,51 +118,63 @@ private function busLoad(
118118
*/
119119
private function loadBus(string $type, string $name, array $options, ContainerBuilder $container)
120120
{
121+
$serviceBusId = 'prooph_service_bus.' . $name;
121122
$serviceBusDefinition = $container->setDefinition(
122-
sprintf('prooph_service_bus.%s', $name),
123+
$serviceBusId,
123124
new DefinitionDecorator('prooph_service_bus.' . $type . '_bus')
124125
);
125126

126127
if (!empty($options['plugins'])) {
127128
foreach ($options['plugins'] as $index => $util) {
128-
$serviceBusDefinition->addMethodCall('utilize', [new Reference($util)]);
129+
if (! $container->hasDefinition($util)) {
130+
throw new RuntimeException(
131+
"A plugin must be a string representing an configured container service"
132+
);
133+
}
129134
}
130135
}
131-
// define message factory
132-
$messageFactoryId = 'prooph_service_bus.message_factory.' . $name;
133136

134-
$container
135-
->setDefinition(
137+
// define message factory
138+
$messageFactoryId = 'prooph_service_bus.message_factory.'.$name;
139+
$container->setDefinition(
136140
$messageFactoryId,
137141
new DefinitionDecorator($options['message_factory'])
138142
);
139143

144+
140145
// define message factory plugin
141-
$messageFactoryPluginId = 'prooph_service_bus.message_factory_plugin.' . $name;
146+
$messageFactoryPluginId = 'prooph_service_bus.message_factory_plugin.'.$name;
147+
$messageFactoryPluginDefinition = new DefinitionDecorator('prooph_service_bus.message_factory_plugin');
148+
$messageFactoryPluginDefinition->setArguments([new Reference($messageFactoryId)]);
142149

143-
$container
144-
->setDefinition(
150+
$container->setDefinition(
145151
$messageFactoryPluginId,
146-
new DefinitionDecorator('prooph_service_bus.message_factory_plugin')
147-
)
148-
->setArguments([new Reference($messageFactoryId)]);
152+
$messageFactoryPluginDefinition
153+
);
149154

150-
$serviceBusDefinition->addMethodCall('utilize', [new Reference($messageFactoryPluginId)]);
151155

152156
// define router
157+
$routerId = null;
153158
if (!empty($options['router'])) {
154-
$routerId = sprintf('prooph_service_bus.%s.router', $name);
155-
156-
$routerDefinition = $container->setDefinition(
157-
$routerId,
158-
new DefinitionDecorator($options['router']['type'])
159-
);
159+
$routerId = 'prooph_service_bus.' . $name . '.router';
160+
$routerDefinition = new DefinitionDecorator($options['router']['type']);
160161
$routerDefinition->setArguments([$options['router']['routes'] ?? []]);
161-
162-
$serviceBusDefinition->addMethodCall('utilize', [new Reference($routerId)]);
162+
$container->setDefinition($routerId, $routerDefinition);
163163
}
164164

165-
//Add container plugin
166-
$serviceBusDefinition->addMethodCall('utilize', [new Reference('prooph_service_bus.container_plugin')]);
165+
//Attach container plugin
166+
$containerPluginId = 'prooph_service_bus.container_plugin';
167+
$pluginIds = array_filter(array_merge($options['plugins'], [$containerPluginId, $messageFactoryPluginId, $routerId]));
168+
169+
// Wrap the message bus creation into factory to call attachToMessageBus on the plugins
170+
$serviceBusDefinition
171+
->setFactory([new Reference('prooph_service_bus.'.$type.'_bus_factory'), 'create'])
172+
->setArguments(
173+
[
174+
$container->getDefinition('prooph_service_bus.'.$type.'_bus')->getClass(),
175+
new Reference('service_container'),
176+
$pluginIds,
177+
]
178+
);
167179
}
168180
}

src/MessageBusFactory.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* prooph (http://getprooph.org/)
4+
*
5+
* @see https://github.com/prooph/service-bus-symfony-bundle for the canonical source repository
6+
* @copyright Copyright (c) 2017 prooph software GmbH (http://prooph-software.com/)
7+
* @license https://github.com/prooph/service-bus-symfony-bundle/blob/master/LICENSE.md New BSD License
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Prooph\Bundle\ServiceBus;
13+
14+
use Prooph\ServiceBus\MessageBus;
15+
use Symfony\Component\DependencyInjection\ContainerInterface;
16+
17+
class MessageBusFactory
18+
{
19+
public function create(string $class, ContainerInterface $container, array $plugins = []) : MessageBus
20+
{
21+
/** @var MessageBus $bus */
22+
$bus = new $class();
23+
24+
foreach ($plugins as $pluginId) {
25+
$plugin = $container->get($pluginId);
26+
$plugin->attachToMessageBus($bus);
27+
}
28+
29+
return $bus;
30+
}
31+
}

src/Resources/config/command_bus.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
</parameters>
1111

1212
<services>
13-
<service id="prooph_service_bus.command_bus" class="%prooph_service_bus.command_bus.class%" abstract="true" />
13+
<service id="prooph_service_bus.command_bus" class="%prooph_service_bus.command_bus.class%" abstract="true" >
14+
<factory service="prooph_service_bus.command_bus_factory" method="create"/>
15+
</service>
16+
<service id="prooph_service_bus.command_bus_factory" class="%prooph_service_bus.message_bus_factory.class%" public="false"/>
1417
<service id="prooph_service_bus.command_bus_router" class="%prooph_service_bus.command_bus_router.class%" public="false" abstract="true" />
1518
</services>
1619
</container>

src/Resources/config/event_bus.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
</parameters>
1111

1212
<services>
13-
<service id="prooph_service_bus.event_bus" class="%prooph_service_bus.event_bus.class%" abstract="true" />
13+
<service id="prooph_service_bus.event_bus" class="%prooph_service_bus.event_bus.class%" abstract="true" >
14+
<factory service="prooph_service_bus.event_bus_factory" method="create"/>
15+
</service>
16+
<service id="prooph_service_bus.event_bus_factory" class="%prooph_service_bus.message_bus_factory.class%" public="false"/>
1417
<service id="prooph_service_bus.event_bus_router" class="%prooph_service_bus.event_bus_router.class%" public="false" abstract="true" />
1518
</services>
1619
</container>

src/Resources/config/query_bus.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
</parameters>
1111

1212
<services>
13-
<service id="prooph_service_bus.query_bus" class="%prooph_service_bus.query_bus.class%" abstract="true" />
13+
<service id="prooph_service_bus.query_bus" class="%prooph_service_bus.query_bus.class%" abstract="true" >
14+
<factory service="prooph_service_bus.query_bus_factory" method="create"/>
15+
</service>
16+
<service id="prooph_service_bus.query_bus_factory" class="%prooph_service_bus.message_bus_factory.class%" public="false" />
1417
<service id="prooph_service_bus.query_bus_router" class="%prooph_service_bus.query_bus_router.class%" public="false" abstract="true" />
1518
</services>
1619
</container>

src/Resources/config/service_bus.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8+
<parameter key="prooph_service_bus.message_bus_factory.class">Prooph\Bundle\ServiceBus\MessageBusFactory</parameter>
89
<parameter key="prooph_service_bus.message_factory_plugin.class">Prooph\ServiceBus\Plugin\MessageFactoryPlugin</parameter>
910
<parameter key="prooph_service_bus.message_factory.class">Prooph\Common\Messaging\FQCNMessageFactory</parameter>
1011
<parameter key="prooph_service_bus.container_plugin.class">Prooph\ServiceBus\Plugin\ServiceLocatorPlugin</parameter>

test/DependencyInjection/Fixture/Model/AcmeRegisterUserCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class AcmeRegisterUserCommand extends Command implements PayloadConstructa
1919
{
2020
use PayloadTrait;
2121

22-
public function messageName()
22+
public function messageName() : string
2323
{
2424
return 'Acme\RegisterUser';
2525
}

test/DependencyInjection/Fixture/Model/AcmeRegisterUserHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function __invoke(AcmeRegisterUserCommand $command)
2020
$this->lastCommand = $command;
2121
}
2222

23+
public function handle(AcmeRegisterUserCommand $command)
24+
{
25+
$this->lastCommand = $command;
26+
}
27+
2328
public function lastCommand()
2429
{
2530
return $this->lastCommand;

test/DependencyInjection/Fixture/Model/AcmeUserEventListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class AcmeUserEventListener
1515
{
1616
private $lastEvent;
1717

18-
public function onUserWasRegistered(AcmeUserWasRegisteredEvent $event)
18+
public function __invoke(AcmeUserWasRegisteredEvent $event)
19+
{
20+
$this->lastEvent = $event;
21+
}
22+
23+
public function onEvent(AcmeUserWasRegisteredEvent $event)
1924
{
2025
$this->lastEvent = $event;
2126
}

test/DependencyInjection/Fixture/Model/AcmeUserWasRegisteredEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AcmeUserWasRegisteredEvent extends DomainEvent implements PayloadConstruct
1919
{
2020
use PayloadTrait;
2121

22-
public function messageName()
22+
public function messageName() : string
2323
{
2424
return 'Acme\UserWasRegistered';
2525
}

test/DependencyInjection/Fixture/Model/MockPlugin.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
use Prooph\Common\Event\ActionEvent;
1414
use Prooph\Common\Event\ActionEventEmitter;
15-
use Prooph\Common\Event\ActionEventListenerAggregate;
1615
use Prooph\Common\Event\DetachAggregateHandlers;
1716
use Prooph\ServiceBus\MessageBus;
17+
use Prooph\ServiceBus\Plugin\AbstractPlugin;
1818

19-
class MockPlugin implements ActionEventListenerAggregate
19+
class MockPlugin extends AbstractPlugin
2020
{
2121
use DetachAggregateHandlers;
2222

@@ -30,9 +30,13 @@ public function wasFired(): bool
3030
/**
3131
* @param ActionEventEmitter $dispatcher
3232
*/
33-
public function attach(ActionEventEmitter $dispatcher)
33+
public function attachToMessageBus(MessageBus $bus) : void
3434
{
35-
$this->trackHandler($dispatcher->attachListener(MessageBus::EVENT_INITIALIZE, [$this, 'onInitialize']));
35+
$this->trackHandler($bus->attach(
36+
MessageBus::EVENT_DISPATCH,
37+
[$this, 'onInitialize'],
38+
MessageBus::PRIORITY_INITIALIZE
39+
));
3640
}
3741

3842
public function onInitialize(ActionEvent $event)

0 commit comments

Comments
 (0)