Skip to content

Commit

Permalink
make snapshot store factory optional
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jan 22, 2017
1 parent bd7b7c8 commit 05daa45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
9 changes: 5 additions & 4 deletions examples/register_and_change_username.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@
];

$dispatch = Kernel\buildCommandDispatcher(
$factories['eventStore'],
$factories['snapshotStore'],
$commandMap,
$factories['dummyProducer']
$factories['eventStore'],
$factories['dummyProducer'],
$factories['snapshotStore']
);

// uncomment to enable amqp publisher
//$dispatch = Kernel\buildCommandDispatcher(
// $factories['eventStore'],
// $commandMap,
// $factories['eventStore'],
// $factories['amqpProducer'],
// $factories['snapshotStore'],
// $factories['startAmqpTransaction'],
// $factories['commitAmqpTransaction']
//);
Expand Down
12 changes: 8 additions & 4 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* builds a dispatcher to return a function that receives a messages and return the state
*
* usage:
* $dispatch = buildDispatcher($eventStoreFactory, $snapshotStoreFactory, $commandMap, $producerFactory);
* $dispatch = buildDispatcher($commandMap, $eventStoreFactory, $producerFactory, $snapshotStoreFactory);
* $state = $dispatch($message);
*
* $producerFactory is expected to be a callback that returns an instance of Prooph\ServiceBus\Async\MessageProducer.
Expand All @@ -50,17 +50,17 @@
* $message is expected to be an instance of Prooph\Common\Messaging\Message
*/
function buildCommandDispatcher(
callable $eventStoreFactory,
callable $snapshotStoreFactory,
array $commandMap,
callable $eventStoreFactory,
callable $producerFactory,
callable $snapshotStoreFactory = null,
callable $startProducerTransaction = null,
callable $commitProducerTransaction = null
): callable {
return function (Message $message) use (
$commandMap,
$eventStoreFactory,
$snapshotStoreFactory,
$commandMap,
$producerFactory,
$startProducerTransaction,
$commitProducerTransaction
Expand All @@ -70,6 +70,10 @@ function buildCommandDispatcher(
};

$loadState = function (AggregateDefiniton $definiton) use ($message, $snapshotStoreFactory): array {
if (null === $snapshotStoreFactory) {
return [];
}

return loadState($snapshotStoreFactory(), $message, $definiton);
};

Expand Down
16 changes: 8 additions & 8 deletions tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function it_builds_command_dispatcher_and_dispatches(): void
};

$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher(
$eventStoreFactory,
$snapshotStoreFactory,
$commandMap,
$producerFactory
$eventStoreFactory,
$producerFactory,
$snapshotStoreFactory
);

$command = $this->prophesize(Message::class);
Expand Down Expand Up @@ -141,10 +141,10 @@ public function it_builds_command_dispatcher_and_dispatches_with_transactional_p
};

$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher(
$eventStoreFactory,
$snapshotStoreFactory,
$commandMap,
$eventStoreFactory,
$producerFactory,
$snapshotStoreFactory,
$start,
$commit
);
Expand Down Expand Up @@ -202,10 +202,10 @@ public function it_builds_command_dispatcher_and_dispatches_but_breaks_when_hand
};

$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher(
$eventStoreFactory,
$snapshotStoreFactory,
$commandMap,
$producerFactory
$eventStoreFactory,
$producerFactory,
$snapshotStoreFactory
);

$command = $this->prophesize(Message::class);
Expand Down

0 comments on commit 05daa45

Please sign in to comment.