chgst/chgst-bundle

chgst 的 Symfony 扩展包

0.3.3 2023-10-21 16:26 UTC

This package is auto-updated.

Last update: 2024-09-21 18:29:45 UTC


README

Version CircleCI Coverage Status License

安装前

确保您已安装 Symfony Security

composer require security

安装

composer require chgst/chgst-bundle

配置

设置事件存储库服务,以将事件持久化到数据存储

# 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

将存储库服务添加到您的服务配置

# 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'

为您的活动创建 Doctrine 模型类

<?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;
    }
}

并添加 XML 映射

<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>