Skip to content

Commit

Permalink
Merge 6d65d68 into b861b0e
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jul 13, 2017
2 parents b861b0e + 6d65d68 commit 9e2d78d
Show file tree
Hide file tree
Showing 16 changed files with 898 additions and 525 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"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"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand All @@ -42,6 +42,7 @@
"Prooph\\Micro\\": "src/"
},
"files": [
"src/Functional.php",
"src/Kernel.php"
]
},
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.

30 changes: 5 additions & 25 deletions examples/register_and_change_username.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use Prooph\Micro\Kernel;
use Prooph\MicroExample\Infrastructure\UserAggregateDefinition;
use Prooph\MicroExample\Model\Command\ChangeUserName;
use Prooph\MicroExample\Model\Command\InvalidCommand;
use Prooph\MicroExample\Model\Command\RegisterUser;
use Prooph\MicroExample\Model\Command\UnknownCommand;
use Prooph\MicroExample\Model\User;

$start = microtime(true);
Expand All @@ -43,35 +41,17 @@
],
];

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

$command = new RegisterUser(['id' => '1', 'name' => 'Alex', 'email' => 'member@getprooph.org']);

$events = $dispatch($command);
$dispatch($command);

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

$events = $dispatch(new ChangeUserName(['id' => '1', 'name' => 'Sascha']));
$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";
echo "Username changed\n";

$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
2 changes: 1 addition & 1 deletion 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 Down
Loading

0 comments on commit 9e2d78d

Please sign in to comment.