flux-eco/aggregate-root

管理以JSON模式描述的聚合根

安装: 29

依赖: 1

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 0

类型:flux-app

1.1.0 2022-04-26 18:24 UTC

This package is auto-updated.

Last update: 2024-09-30 01:27:06 UTC


README

管理以JSON模式描述的聚合根。在存储中评估和存储事件。到目前为止,此组件绑定到MySQL存储。存储可以被进一步适配器的实现所替换。

以下示例应用程序演示了用法:https://github.com/flux-caps/todo-app

用法

.env

AGGREGATE_ROOT_SCHEMA_DIRECTORY=schemas/domain
AGGREGATE_ROOT_STORAGE_CONFIG_ENV_PREFIX=EVENTS_
AGGREGATE_ROOT_EVENT_SCHEMA_FILE_PATH=../schemas/AggregateRootEvent.yaml
EVENTS_STORAGE_HOST=localhost
EVENTS_STORAGE_DRIVER=Pdo_Mysql
EVENTS_STORAGE_NAME=events
EVENTS_STORAGE_USER=user
EVENTS_STORAGE_PASSWORD=password
PROJECTION_APP_SCHEMA_DIRECTORY=../vendor/flux-eco/projection/schemas
PROJECTION_ECO_SCHEMA_DIRECTORY=schemas/projections
PROJECTION_STORAGE_CONFIG_ENV_PREFIX=PROJECTION_
PROJECTION_STORAGE_NAME=projection
PROJECTION_STORAGE_HOST=localhost
PROJECTION_STORAGE_DRIVER=Pdo_Mysql
PROJECTION_STORAGE_USER=user
PROJECTION_STORAGE_PASSWORD=password
STREAM_STORAGE_CONFIG_ENV_PREFIX=STREAM_
STREAM_STORAGE_NAME=stream
STREAM_STORAGE_HOST=localhost
STREAM_STORAGE_DRIVER=Pdo_Mysql
STREAM_STORAGE_USER=user
STREAM_STORAGE_PASSWORD=password
STREAM_TABLE_NAME=stream
STREAM_STATE_SCHEMA_FILE=../vendor/flux-eco/global-stream/schemas/State.yaml

schemas\domain\account.yaml

name: account
type: object
properties:
    aggregateId:
        type: string
        readOnly: true
    correlationId:
        type: string
        readOnly: true
    aggregateName:
        type: string
        const: todo
        readOnly: true
    sequence:
        type: integer
        readOnly: true
    createdDateTime:
        type: string
        format: date-time
        readOnly: true
    createdBy:
        type: string
        format: email
        readOnly: true
    changedDateTime:
        type: string
        format: date-time
        readOnly: true
    changedBy:
        type: string
        format: email
        readOnly: true
    rootObjectSchema:
        type: string
        const: v1
    rootObject:
        type: object
        properties:
            firstname:
                type: string
            lastname:
                type: string

schemas\projections\account.yaml

title: account
type: object
aggregateRootNames:
  - account
properties:
  projectionId:
    type: string
  firstname:
    type: string
    index: account.rootObject.firstname
  lastname:
    type: string
    index: account.rootObject.lastname

example.php

<?php

require_once __DIR__ . '/../vendor/autoload.php';

FluxEco\DotEnv\Api::new()->load(__DIR__);

//initialize
fluxAggregateRoot\initialize();

//create
$correlationId = fluxValueObject\getNewUuid();
$actorEmail = 'example@fluxlabs.ch';
$aggregateName = 'account';
$aggregateId = fluxValueObject\getNewUuid();
$payload = json_encode([
   "firstname" => "Emmett",
   "lastname" => "Brown"
]);
fluxAggregateRoot\create($correlationId, $actorEmail, $aggregateName, $aggregateId, $payload);


//change
$correlationId = fluxValueObject\getNewUuid();
$payload = json_encode([
    "firstname" => "Dr. Emmett",
    "lastname" => "Brown"
]);
fluxAggregateRoot\change($correlationId, $actorEmail, $aggregateName, $aggregateId, $payload);

//delete
fluxAggregateRoot\delete($correlationId, $actorEmail, $aggregateName, $aggregateId);

贡献 💜

请...

  1. ...在 https://git.fluxlabs.ch 注册账户
  2. ...创建拉取请求 🔥

调整建议 / 错误报告 🐾

请...

  1. ...在 https://git.fluxlabs.ch 注册账户
  2. ...向我们请求服务水平协议:support@fluxlabs.ch 😘
  3. ...阅读和创建问题