-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.php
55 lines (45 loc) · 2.26 KB
/
config.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace {
use App\Model\Command\ChangeEmail;
use App\Model\Command\ChangeEmailHandler;
use App\Model\Command\RegisterUser;
use App\Model\Command\RegisterUserHandler;
use App\Model\Event\EmailChanged;
use App\Model\Event\UserRegistered;
use App\Infrastructure\UserRepository;
use App\Projection\UserProjector;
use Prooph\Common\Event\ProophActionEventEmitter;
use Prooph\Common\Messaging\FQCNMessageFactory;
use Prooph\EventStore\ActionEventEmitterEventStore;
use Prooph\EventStore\Pdo\MySqlEventStore;
use Prooph\EventStore\Pdo\PersistenceStrategy\MySqlAggregateStreamStrategy;
use Prooph\EventStore\Pdo\Projection\MySqlProjectionManager;
use Prooph\EventStoreBusBridge\EventPublisher;
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\EventBus;
use Prooph\ServiceBus\Plugin\Router\CommandRouter;
use Prooph\ServiceBus\Plugin\Router\EventRouter;
use Prooph\SnapshotStore\Pdo\PdoSnapshotStore;
include "./vendor/autoload.php";
$pdo = new PDO('mysql:dbname=prooph;host=localhost', 'root', '');
$eventStore = new MySqlEventStore(new FQCNMessageFactory(), $pdo, new MySqlAggregateStreamStrategy());
$eventEmitter = new ProophActionEventEmitter();
$eventStore = new ActionEventEmitterEventStore($eventStore, $eventEmitter);
$eventBus = new EventBus($eventEmitter);
$eventPublisher = new EventPublisher($eventBus);
$eventPublisher->attachToEventStore($eventStore);
$pdoSnapshotStore = new PdoSnapshotStore($pdo);
$userRepository = new UserRepository($eventStore, $pdoSnapshotStore);
$projectionManager = new MySqlProjectionManager($eventStore, $pdo);
$commandBus = new CommandBus();
$router = new CommandRouter();
$router->route(RegisterUser::class)->to(new RegisterUserHandler($userRepository));
$router->route(ChangeEmail::class)->to(new ChangeEmailHandler($userRepository));
$router->attachToMessageBus($commandBus);
$userProjector = new UserProjector($pdo);
$eventRouter = new EventRouter();
$eventRouter->route(EmailChanged::class)->to([$userProjector, 'onEmailChanged']);
$eventRouter->route(UserRegistered::class)->to([$userProjector, 'onUserRegistered']);
$eventRouter->attachToMessageBus($eventBus);
$userId = '20';
}