-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump service bus package #10
Changes from 6 commits
a71c7a3
d8e7572
827e217
88f24d8
7d2db30
f39c7c1
563da87
e445666
caa56f3
b7f97d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ | |
|
||
namespace Prooph\Bundle\ServiceBus\DependencyInjection; | ||
|
||
use Prooph\Bundle\ServiceBus\Exception\RuntimeException; | ||
use Prooph\ServiceBus\CommandBus; | ||
use Prooph\ServiceBus\EventBus; | ||
use Prooph\ServiceBus\QueryBus; | ||
use Prooph\ServiceBus\Plugin\Router\CommandRouter; | ||
use Prooph\ServiceBus\Plugin\Router\EventRouter; | ||
use Prooph\ServiceBus\Plugin\Router\QueryRouter; | ||
use Prooph\ServiceBus\QueryBus; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\DefinitionDecorator; | ||
|
@@ -35,6 +36,7 @@ final class ProophServiceBusExtension extends Extension | |
'query' => QueryBus::class, | ||
]; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two empty lines intended? |
||
public function getNamespace() | ||
{ | ||
return 'http://getprooph.org/schemas/symfony-dic/prooph'; | ||
|
@@ -118,51 +120,64 @@ private function busLoad( | |
*/ | ||
private function loadBus(string $type, string $name, array $options, ContainerBuilder $container) | ||
{ | ||
$serviceBusName = sprintf('prooph_service_bus.%s', $name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String concatenation is used 8 times while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$serviceBusDefinition = $container->setDefinition( | ||
sprintf('prooph_service_bus.%s', $name), | ||
$serviceBusName, | ||
new DefinitionDecorator('prooph_service_bus.' . $type . '_bus') | ||
); | ||
|
||
if (!empty($options['plugins'])) { | ||
foreach ($options['plugins'] as $index => $util) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused variable |
||
$serviceBusDefinition->addMethodCall('utilize', [new Reference($util)]); | ||
if (! $container->hasDefinition($util)) { | ||
throw new RuntimeException( | ||
"A plugin must be a string representing an configured container service" | ||
); | ||
} | ||
} | ||
} | ||
// define message factory | ||
$messageFactoryId = 'prooph_service_bus.message_factory.' . $name; | ||
|
||
$container | ||
->setDefinition( | ||
// define message factory | ||
$messageFactoryId = 'prooph_service_bus.message_factory.'.$name; | ||
$container->setDefinition( | ||
$messageFactoryId, | ||
new DefinitionDecorator($options['message_factory']) | ||
); | ||
|
||
|
||
// define message factory plugin | ||
$messageFactoryPluginId = 'prooph_service_bus.message_factory_plugin.' . $name; | ||
$messageFactoryPluginId = 'prooph_service_bus.message_factory_plugin.'.$name; | ||
$messageFactoryPluginDefinition = new DefinitionDecorator('prooph_service_bus.message_factory_plugin'); | ||
$messageFactoryPluginDefinition->setArguments([new Reference($messageFactoryId)]); | ||
|
||
$container | ||
->setDefinition( | ||
$container->setDefinition( | ||
$messageFactoryPluginId, | ||
new DefinitionDecorator('prooph_service_bus.message_factory_plugin') | ||
) | ||
->setArguments([new Reference($messageFactoryId)]); | ||
$messageFactoryPluginDefinition | ||
); | ||
|
||
$serviceBusDefinition->addMethodCall('utilize', [new Reference($messageFactoryPluginId)]); | ||
|
||
// define router | ||
$routerId = null; | ||
if (!empty($options['router'])) { | ||
$routerId = sprintf('prooph_service_bus.%s.router', $name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above about |
||
|
||
$routerDefinition = $container->setDefinition( | ||
$routerId, | ||
new DefinitionDecorator($options['router']['type']) | ||
); | ||
$routerDefinition = new DefinitionDecorator($options['router']['type']); | ||
$routerDefinition->setArguments([$options['router']['routes'] ?? []]); | ||
|
||
$serviceBusDefinition->addMethodCall('utilize', [new Reference($routerId)]); | ||
$container->setDefinition($routerId, $routerDefinition); | ||
} | ||
|
||
//Add container plugin | ||
$serviceBusDefinition->addMethodCall('utilize', [new Reference('prooph_service_bus.container_plugin')]); | ||
//Attach container plugin | ||
$containerPluginId = 'prooph_service_bus.container_plugin'; | ||
$pluginIds = array_filter(array_merge($options['plugins'], [$containerPluginId, $messageFactoryPluginId, $routerId])); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two empty lines intended? |
||
// Wrap the message bus creation into factory to call attachToMessageBus on the plugins | ||
$serviceBusDefinition | ||
->setFactory([new Reference('prooph_service_bus.'.$type.'_bus_factory'), 'create']) | ||
->setArguments( | ||
[ | ||
$container->getDefinition('prooph_service_bus.'.$type.'_bus')->getClass(), | ||
new Reference('service_container'), | ||
$pluginIds, | ||
] | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* prooph (http://getprooph.org/) | ||
* | ||
* @see https://github.com/prooph/service-bus-symfony-bundle for the canonical source repository | ||
* @copyright Copyright (c) 2017 prooph software GmbH (http://prooph-software.com/) | ||
* @license https://github.com/prooph/service-bus-symfony-bundle/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prooph\Bundle\ServiceBus; | ||
|
||
use Prooph\ServiceBus\MessageBus; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class MessageBusFactory | ||
{ | ||
public function create(string $class, ContainerInterface $container, array $plugins = []) : MessageBus | ||
{ | ||
/** @var MessageBus $bus */ | ||
$bus = new $class(); | ||
|
||
foreach ($plugins as $pluginId) { | ||
$plugin = $container->get($pluginId); | ||
$plugin->attachToMessageBus($bus); | ||
} | ||
|
||
return $bus; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
</parameters> | ||
|
||
<services> | ||
<service id="prooph_service_bus.command_bus" class="%prooph_service_bus.command_bus.class%" abstract="true" /> | ||
<service id="prooph_service_bus.command_bus" class="%prooph_service_bus.command_bus.class%" abstract="true" > | ||
<factory service="prooph_service_bus.command_bus_factory" method="create"/> | ||
</service> | ||
<service id="prooph_service_bus.command_bus_factory" class="%prooph_service_bus.message_bus_factory.class%"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure but factory might be set to |
||
<service id="prooph_service_bus.command_bus_router" class="%prooph_service_bus.command_bus_router.class%" public="false" abstract="true" /> | ||
</services> | ||
</container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
</parameters> | ||
|
||
<services> | ||
<service id="prooph_service_bus.event_bus" class="%prooph_service_bus.event_bus.class%" abstract="true" /> | ||
<service id="prooph_service_bus.event_bus" class="%prooph_service_bus.event_bus.class%" abstract="true" > | ||
<factory service="prooph_service_bus.event_bus_factory" method="create"/> | ||
</service> | ||
<service id="prooph_service_bus.event_bus_factory" class="%prooph_service_bus.message_bus_factory.class%"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. |
||
<service id="prooph_service_bus.event_bus_router" class="%prooph_service_bus.event_bus_router.class%" public="false" abstract="true" /> | ||
</services> | ||
</container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
</parameters> | ||
|
||
<services> | ||
<service id="prooph_service_bus.query_bus" class="%prooph_service_bus.query_bus.class%" abstract="true" /> | ||
<service id="prooph_service_bus.query_bus" class="%prooph_service_bus.query_bus.class%" abstract="true" > | ||
<factory service="prooph_service_bus.query_bus_factory" method="create"/> | ||
</service> | ||
<service id="prooph_service_bus.query_bus_factory" class="%prooph_service_bus.message_bus_factory.class%"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. |
||
<service id="prooph_service_bus.query_bus_router" class="%prooph_service_bus.query_bus_router.class%" public="false" abstract="true" /> | ||
</services> | ||
</container> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prooph now has custom templates!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see: https://github.com/prooph/bookdown-template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will apply that.