The message repository will store the event messages where and how you want them to be stored. This is usually a database but could be anywhere. The Aggregate Repository uses the Message Repository to save the event messages that were raised.
Usage
<?phpuseSonsOfPHP\Component\EventSourcing\Message\Repository\MessageRepositoryInterface;useSonsOfPHP\Component\EventSourcing\Message\MessageInterface;useSonsOfPHP\Component\EventSourcing\Aggregate\AggregateIdInterface;useSonsOfPHP\Component\EventSourcing\Aggregate\AggregateVersionInterface;// @var MessageRepositoryInterface $messageRepository// @var MessageInterface $message$messageRepository->persist($message);// @var AggregateIdInterface|string $aggregateId// @var MessageInterface[] $eventMessages$eventMessages = $messageRepository->find($aggregateId);// or to grab event messages after a specific version// @var AggregateVersionInterface|int $aggregateVersion$eventMessages = $messageRepository->find($aggregateId, $aggregateVersion);
InMemoryMessageRepository
This repository is mainly used for testing, however to keep the examples easy we will start with this message repository.
The TableSchemaInterface defines what table to use along with the columns and mapping information. They are easy to work with and create custom schemas.