Download the PHP package twanhaverkamp/event-storage-in-mongodb-with-php without Composer
On this page you can find all versions of the php package twanhaverkamp/event-storage-in-mongodb-with-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download twanhaverkamp/event-storage-in-mongodb-with-php
More information about twanhaverkamp/event-storage-in-mongodb-with-php
Files in twanhaverkamp/event-storage-in-mongodb-with-php
Package event-storage-in-mongodb-with-php
Short Description Event Storage in MongoDB with PHP
License MIT
Informations about the package event-storage-in-mongodb-with-php
Event storage in MongoDB with PHP
This package is a MongoDB implementation for the "Event Sourcing with PHP" library.
Table of Contents
- Usage
- Installation
- Implementation
- Connect with MongoDB
- Event storage
- Dependency injection
- Laravel project
- Symfony project
Usage
Installation
Requirements:
- PHP 8.3 (or higher)
If you're using Composer in your project you can run the following command:
Implementation
Most PHP frameworks like Symfony and Laravel allows you to register classes as services; If you like, you can register this Event store where you bind it to the EventStoreInterface.
Connect with MongoDB
When constructing the MongoDB client as first argument, an Event describer instance as second argument and your Database and Collection names as third and fourth arguments.
An Event describer can be found in the "Event Sourcing with PHP" library, which is automatically installed whenever you install this package. You can create your own Describer if you like; just make sure it implements the EventDescriberInterface, which can also be found in the "Event Sourcing with PHP" library.
Event registration
In order for the Event Store to know which type of Events exist, you need to register them in the Event Store:
You have to register your Events before actually using the Event Store.
Event storage
When you pass an Aggregate to the save function it loops over its Events and for every Event it will insert
a new "document" for the constructed Database and Collection names.
Dependency injection
Laravel project
Create your own service provider when your working in a Laravel project to bind the MongoDB class to the EventStoreInterface:
Symfony project
If you're working in a Symfony project, you can leverage it's built-in "autowire" mechanism
by registering the Event Store as a service in the services.yaml:
All versions of event-storage-in-mongodb-with-php with dependencies
ext-mongodb Version *
mongodb/mongodb Version ^2.1
twanhaverkamp/event-sourcing-with-php Version ^1.3