chgst/chgst-bundle

Symfony bundle for chgst

0.3.3 2023-10-21 16:26 UTC

This package is auto-updated.

Last update: 2024-11-21 18:48:14 UTC


README

Version CircleCI Coverage Status License

Before Install

Make sure you have Symfony Security installed:

composer require security

Installation

composer require chgst/chgst-bundle

Configuration

Set your event repository service for persisting events to data store

# config/packages/chgst.yaml
chgst:
  enable_listeners: true

# Make sure you disable listeners in test/dev environment
when@dev:
  chgst:
    enable_listeners: false

when@test:
  chgst:
    enable_listeners: false

Add repository service to your services configuration

# config/services.yaml
services:

    Chgst\Event\RepositoryInterface:
        public: true
        class: Chgst\Event\ObjectRepository
        arguments: [ '@doctrine_mongodb.odm.document_manager', 'App\Document\DefaultEvent' ] # or '@doctrine.orm.entity_manager'

Create Doctrine model class for your events

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

namespace App\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;
    }
}

And add XML 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="App\Document\DefaultEvent">
        <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="createdAt" type="date" nullable="false" />
        <field field-name="createdBy" type="string" nullable="false" />
        <field field-name="payload" type="hash" nullable="false" />
    </document>
</doctrine-mongo-mapping>