-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
29 lines (24 loc) · 1.05 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
use EventSauce\EventSourcing\AggregateRootRepository;
use EventSauce\EventSourcing\ConstructingAggregateRootRepository;
use EventSauce\EventSourcing\SynchronousMessageDispatcher;
use EventSauce\ExampleProject\ExampleAggregate;
use EventSauce\ExampleProject\ExampleConsumer;
use EventSauce\ExampleProject\ExampleId;
use EventSauce\ExampleProject\JsonMessageRepository;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
include __DIR__ . '/vendor/autoload.php';
/** @var AggregateRootRepository<ExampleAggregate> $repository */
$repository = new ConstructingAggregateRootRepository(
ExampleAggregate::class,
new JsonMessageRepository(new Filesystem(new LocalFilesystemAdapter(__DIR__.'/messages/'))),
new SynchronousMessageDispatcher(
new ExampleConsumer(create_clock())
)
);
/** @var ExampleAggregate $exampleAggregate */
$exampleAggregate = $repository->retrieve(new ExampleId('this-is-the-id'));
$exampleAggregate->performAction(bin2hex(random_bytes(10)));
//
$repository->persist($exampleAggregate);