chgst/persistence-doctrine

Doctrine implementation for data store

0.3.0 2023-10-08 17:00 UTC

This package is auto-updated.

Last update: 2024-12-08 19:19:06 UTC


README

Version CircleCI Coverage Status License

Installation

composer require chgst/persistence-doctrine

Configuration

Create your model class:

<?php
// src/Document/DefaultEvent.php

namespace Document;

use Chgst\Event\Event;

class DefaultEvent extends Event
{
    protected string $id;

    public function getId(): string
    {
        return $this->id;
    }

    public function setId(string $id): self
    {
        $this->id = $id;

        return $this;
    }
}

Add mapping

 <doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
                    https://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

    <document name="Document\Event">
        <id />
        <field field-name="name" type="string" nullable="false" />
        <field field-name="aggregateType" type="string" nullable="false" />
        <field field-name="aggregateId" type="string" nullable="false" />
        <field field-name="payload" type="hash" nullable="false" />
        <field field-name="createdAt" type="date" nullable="false" />
        <field field-name="createdBy" type="string" nullable="false" />
    </document>
</doctrine-mongo-mapping>