Skip to content

Commit

Permalink
Merge pull request #43 from othillo/disable-saga-by-default
Browse files Browse the repository at this point in the history
 saga should not be enabled by default
  • Loading branch information
asm89 authored Nov 17, 2017
2 parents 915633b + 22cbb0d commit 0443b4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/BroadwayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$this->loadCommandBus($mergedConfig['command_handling'], $container, $loader);
$this->loadSerializers($mergedConfig['serializer'], $container, $loader);

if (isset($mergedConfig['saga'])) {
if (isset($mergedConfig['saga']) && isset($mergedConfig['saga']['enabled']) && $mergedConfig['saga']['enabled']) {
$loader->load('saga.xml');

if (isset($mergedConfig['saga']['state_repository'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class RegisterSagaStateRepositoryCompilerPass extends CompilerPass
{
public function process(ContainerBuilder $container)
{
if (! $container->hasDefinition('broadway.saga.state.in_memory_repository')) {
return;
}

$serviceParameter = 'broadway.saga.state.repository.service_id';
if (! $container->hasParameter($serviceParameter)) {
$container->setAlias(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Broadway\Bundle\BroadwayBundle\DependencyInjection;

use Broadway\EventStore\EventStore;
use Broadway\Saga\State\RepositoryInterface;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -24,6 +23,8 @@ class RegisterSagaStateRepositoryCompilerPassTest extends AbstractCompilerPassTe
*/
protected function registerCompilerPass(ContainerBuilder $container)
{
$this->setDefinition('broadway.saga.state.in_memory_repository', new Definition(RepositoryInterface::class));

$container->addCompilerPass(new RegisterSagaStateRepositoryCompilerPass());
}

Expand Down
9 changes: 9 additions & 0 deletions test/DependencyInjection/Extension/SagaExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ protected function getContainerExtensions()
];
}

/**
* @test
*/
public function it_does_not_register_the_saga_state_manager_service_when_not_configured()
{
$this->load([]);

$this->assertFalse($this->container->hasDefinition('broadway.saga.state.state_manager'));
}

/**
* @test
Expand Down

0 comments on commit 0443b4f

Please sign in to comment.