<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m1x0n / eventsauce-mongo-message-repository example snippets
$mongoDbName = 'mydb';
$eventsCollectionName = 'events';
// Initialize mongo client and select target database
$client = new MongoDB\Client(
null,
[
'username' => 'user',
'password' => 'secret'
]
);
$database = $client->selectDatabase($mongoDbName);
// Configure message repository or see MongoDbMessageRepositoryFactory
$messageRepository = new \EventSauceExtensions\MongoDbMessageRepository(
$database,
new \EventSauceExtensions\MongoDbMessageSerializer(
new \EventSauce\EventSourcing\Serialization\ConstructingMessageSerializer()
),
$eventsCollectionName
);
// MongoDbMessageSerializer also supports upcasting.
// Upcasting is possible by passing upcaster itself as second argument
// This is mostly for example and can be replaced with MessageBus dispatcher like RabbitMQ.
// See eventsauce/rabbitmq-bundle-bindings
$messageDispatcher = new \EventSauce\EventSourcing\SynchronousMessageDispatcher();
// MyAggregateClass must implement
$bulbsAggregateRepository = new \EventSauce\EventSourcing\ConstructingAggregateRootRepository(
MyAggreateClass::class,
$messageRepository,
$messageDispatcher
);