Skip to content

Commit

Permalink
Merge c4c0d14 into b861b0e
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jul 16, 2017
2 parents b861b0e + c4c0d14 commit 6cfe3f8
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 480 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"prooph"
],
"require": {
"prooph/event-store": "^7.0",
"prooph/pdo-event-store": "^1.0",
"prooph/snapshot-store": "^1.0"
"prooph/event-store": "^7.2",
"prooph/pdo-event-store": "^1.4.1",
"prooph/snapshot-store": "^1.2",
"phunkie/phunkie": "^0.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/Infrastructure/UserAggregateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\StreamName;
use Prooph\Micro\AbstractAggregateDefiniton;
use Prooph\Micro\AbstractAggregateDefinition;
use Prooph\MicroExample\Model\User;

final class UserAggregateDefinition extends AbstractAggregateDefiniton
final class UserAggregateDefinition extends AbstractAggregateDefinition
{
public function aggregateType(): string
{
Expand Down
11 changes: 11 additions & 0 deletions examples/Infrastructure/factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Prooph\EventStore\EventStore;
use Prooph\EventStore\InMemoryEventStore;
use Prooph\EventStore\Projection\InMemoryProjectionManager;
use Prooph\MicroExample\Infrastructure\InMemoryEmailGuard;
use Prooph\MicroExample\Model\UniqueEmailGuard;
use Prooph\SnapshotStore\InMemorySnapshotStore;
Expand Down Expand Up @@ -47,4 +48,14 @@
},
];

$factories['projectionManager'] = function () use (&$factories): InMemoryProjectionManager {
static $manager = null;

if (null === $manager) {
$manager = new InMemoryProjectionManager($factories['eventStore']());
}

return $manager;
};

return $factories;
13 changes: 0 additions & 13 deletions examples/Model/user_snapshotter.php

This file was deleted.

40 changes: 15 additions & 25 deletions examples/register_and_change_username.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Prooph\MicroExample\Script;

use Phunkie\Validation\Validation;
use Prooph\Common\Messaging\Message;
use Prooph\Micro\Kernel;
use Prooph\MicroExample\Infrastructure\UserAggregateDefinition;
Expand Down Expand Up @@ -43,35 +44,24 @@
],
];

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

$command = new RegisterUser(['id' => '1', 'name' => 'Alex', 'email' => 'member@getprooph.org']);
/* @var Validation $result */
$result = $dispatch(new RegisterUser(['id' => '1', 'name' => 'Alex', 'email' => 'member@getprooph.org']));
echo $result->show() . PHP_EOL;
echo json_encode($result->getOrElse('')->head()->payload()) . PHP_EOL . PHP_EOL;

$events = $dispatch($command);
$result = $dispatch(new ChangeUserName(['id' => '1', 'name' => 'Sascha']));
echo $result->show() . PHP_EOL;
echo json_encode($result->getOrElse('')->head()->payload()) . PHP_EOL . PHP_EOL;

echo "User was registered, emitted event payload: \n";
echo json_encode($events[0]->payload()) . "\n\n";
// a TypeError
$result = $dispatch(new InvalidCommand());
echo $result->show() . PHP_EOL . PHP_EOL;

$events = $dispatch(new ChangeUserName(['id' => '1', 'name' => 'Sascha']));

echo "Username changed, emitted event payload: \n";
echo json_encode($events[0]->payload()) . "\n\n";

// should return a TypeError
$throwable = $dispatch(new InvalidCommand());

echo get_class($throwable) . "\n";
echo $throwable->getMessage() . "\n\n";

$throwable = $dispatch(new UnknownCommand());

// should return a RuntimeException
echo get_class($throwable) . "\n";
echo $throwable->getMessage() . "\n\n";
// unknown command
$result = $dispatch(new UnknownCommand());
echo $result->show() . PHP_EOL . PHP_EOL;

$time = microtime(true) - $start;

Expand Down
9 changes: 4 additions & 5 deletions examples/user_snapshotter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Prooph\MicroExample\Script;

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Projection\ProjectionManager;
use Prooph\Micro\SnapshotReadModel;
use Prooph\MicroExample\Infrastructure\UserAggregateDefinition;

Expand All @@ -24,16 +24,15 @@
//We could also use a container here, if dependencies grow
$factories = include 'Infrastructure/factories.php';

$eventStore = $factories['eventStore']();

/* @var EventStore $eventStore */
/* @var ProjectionManager $projectionManager */
$projectionManager = $factories['projectionManager']();

$readModel = new SnapshotReadModel(
$factories['snapshotStore'](),
new UserAggregateDefinition()
);

$projection = $eventStore->createReadModelProjection(
$projection = $projectionManager->createReadModelProjection(
'user_snapshots',
$readModel
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Prooph\EventStore\Metadata\Operator;
use RuntimeException;

abstract class AbstractAggregateDefiniton implements AggregateDefiniton
abstract class AbstractAggregateDefinition implements AggregateDefinition
{
public function identifierName(): string
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public function metadataMatcher(string $aggregateId, int $aggregateVersion): ?Me
->withMetadataMatch('_aggregate_version', Operator::GREATER_THAN_EQUALS(), $aggregateVersion);
}

public function metadataEnricher(string $aggregateId, int $aggregateVersion): ?MetadataEnricher
public function metadataEnricher(string $aggregateId, int $aggregateVersion, Message $causation = null): ?MetadataEnricher
{
return new class($aggregateId, $this->aggregateType(), $aggregateVersion) implements MetadataEnricher {
private $aggregateId;
Expand Down
4 changes: 2 additions & 2 deletions src/AggregateDefiniton.php → src/AggregateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Prooph\EventStore\Metadata\MetadataMatcher;
use Prooph\EventStore\StreamName;

interface AggregateDefiniton
interface AggregateDefinition
{
public function aggregateType(): string;

Expand All @@ -38,7 +38,7 @@ public function extractAggregateVersion(Message $message): int;

public function streamName(): StreamName;

public function metadataEnricher(string $aggregateId, int $aggregateVersion): ?MetadataEnricher;
public function metadataEnricher(string $aggregateId, int $aggregateVersion, Message $causation = null): ?MetadataEnricher;

public function metadataMatcher(string $aggregateId, int $aggregateVersion): ?MetadataMatcher;

Expand Down
Loading

0 comments on commit 6cfe3f8

Please sign in to comment.